fork(17) download
  1. // meize1.cpp : 16*16 マイクロマウス(クラッシック規定)向け 迷路探索プログラム
  2. // Copyrights (C) 2013,manygods000.
  3. // license :licensed from above.
  4. // Mozilla Public License 2.0 (MPL-2.0) http://o...content-available-to-author-only...e.org/licenses/MPL-2.0
  5. // See also http://o...content-available-to-author-only...m.jp/node/498
  6. // initial coder: manygods000 at my.chiebukuro.yahoo.co.jp.
  7. // ライセンスの補足;
  8. // 貴方は、このプログラムを自由に改変して使用することができます。
  9. // 貴方が、このプログラムまたは、貴方による改変板のプログラムを頒布する場合、
  10. // 貴方には、幾つかの義務が生じます。
  11. // 貴方は、initial coderには、改変版のソースコードを開示する義務を負います。
  12. // GPLとは異なって、貴方にとっての下流の頒布先にまで、貴方によって改変された
  13. // ソースコードを開示する必要はありません。
  14. // 貴方が頒布したソースコードにより将来発生しうる特許に関する主張を放棄する義務を負います。
  15. // より厳格な解釈は、日本OSSフォーラム等の解説をご覧ください.
  16. //
  17. #define _CRT_SECURE_NO_WARNINGS
  18. #include <iostream>
  19. #include <fstream>
  20. #include <stdlib.h>
  21. #ifdef _CRT_NONSTDC_DEPRECATE
  22. #include <conio.h>
  23. #endif
  24. #include <time.h>
  25.  
  26. using namespace std;
  27.  
  28. //#include "stdlib.h"
  29. #include "string.h"
  30.  
  31. #define handDebugMode 0
  32. #define MAPSIZE 16
  33. #define MAPDISPLAYSIZEy (MAPSIZE*2)
  34. #define MAPDISPLAYSIZEx (MAPSIZE*3+3)
  35.  
  36. typedef struct {
  37. bool n;
  38. bool w;
  39. bool s;
  40. bool e;
  41. bool isGoal;
  42. bool isStart;
  43. bool isVisited;
  44. } Walls_t;
  45. typedef union {
  46. unsigned int data;
  47. Walls_t f;
  48. } Walls;
  49. typedef enum mdir {n=0,w=1,s=2,e=3} mdir_t;
  50. typedef enum rdir {Forwards=0,Right1Quarter=1,Right1Half=2,Right3Quarter=3,
  51. Right=4,Right5Quarter=5,Right3Half=6,Right7Quarter=7,
  52. Backwards=8,Left7Quarter=9,Left3Half=10,Left5Quarter=11,
  53. Left=12,Left3Quarter=13,Left1half=14,Left1Quarter=15} rdir_t; //sizeof(rdir_t)==4
  54. const char rdir_displayStr[16][4]={"F\0\0"/*前方good*/,
  55. "r1q"/*右前方better*/,"rh\0"/*better*/,"r3q"/*better*/,
  56. "R\0\0"/*左good*/,
  57. "r5q"/*右後方Bad*/ ,"r3h"/*Bad*/,"r7q"/*Bad*/ ,
  58. "Bak"/*後ろBad */,
  59. "l7q"/*左後方Bad*/ ,"l3h"/*Bad*/,"l5q"/*Bad*/ ,
  60. "L\0\0"/*左good*/,
  61. "l3q"/*左前方better*/,"lh\0"/*better*/,"l1q"/*better*/};
  62. typedef struct {//相対移動指示コマンドのエレメント
  63. union {
  64. unsigned short int packed1Cmd;
  65. struct {
  66. unsigned short int detailStep:4;//2進固定少数点数、少数部4ビット
  67. signed short int stepCount:8;//2進固定少数点数、整数部8ビット
  68. unsigned short int rDirLo:2;
  69. signed short int rDirHi:2; //前進は0,左が負、右が正
  70. } f;
  71. struct {
  72. unsigned short int Distance:12;//移動距離:2進固定少数点数、整数部8ビットと少数部4ビット
  73. signed short /*rdir_t*/ rDir:4;//2で割ると半分の回転量となる。
  74. } v;
  75. } u;
  76. } rCMD_t; //sizeof(rCMD_t)==2
  77. typedef struct{
  78. unsigned short int x;
  79. unsigned short int y;
  80. } position_t;
  81.  
  82. //c++ section
  83. //inline bool operator == (const Walls_t &it,const Walls_t &the) {return it.n==the.n && it.w==the.w && it.s==the.s && e==the.e && it.isGoal==the.isGoal /*&& it.isVisited==the.isVisited*/; }
  84. inline bool operator == (const Walls &it,const Walls &the) {return it.data==the.data;}
  85. std::ostream& operator<<(std::ostream& os, const mdir_t& curDir)
  86. {
  87. return ( os <<((curDir==n)?'n':(curDir==w)?'w':(curDir==s)?'s':(curDir==e)?'e':'?'));
  88. }
  89. std::ostream& operator<<(std::ostream& os, const rCMD_t& OneCmd)
  90. {
  91. return ( os << '(' << rdir_displayStr[OneCmd.u.v.rDir & 0x0f] << ',' << OneCmd.u.f.stepCount <<'.'<< OneCmd.u.f.detailStep <<')' );
  92. }
  93. std::ostream& operator<<(std::ostream& os, const position_t& curPostion)
  94. {
  95. return ( os << '(' << curPostion.x <<','<< curPostion.y << ')' );
  96. }
  97. typedef struct {
  98. char title1[MAPDISPLAYSIZEx-2];
  99. unsigned char titleTr1[2];
  100. char header1[MAPDISPLAYSIZEx];
  101. union {
  102. char displayLines[MAPDISPLAYSIZEy][MAPDISPLAYSIZEx];
  103. struct {
  104. unsigned char rowsHead1;
  105. unsigned char cols[MAPSIZE][3];
  106. unsigned char rowsTr1[2];
  107. unsigned char rowsHead2;
  108. unsigned char walls[MAPSIZE][3];
  109. unsigned char rowsTr2[2];
  110. } rows[MAPSIZE];
  111. }u;
  112. } extData_t;
  113.  
  114. typedef char displayString_t [sizeof(extData_t)+MAPSIZE];
  115. class extException {};
  116. class extBreak :public extException{};
  117. class invalidPosition :public extException{};
  118. class invalidToGo :public extException{};
  119. class invalidQue :public extException{};
  120. class cannotToGoal :public extException{};
  121.  
  122. class externalData{
  123. extData_t extData;
  124. position_t curPos;
  125. mdir_t curDir;
  126. int option_GoalsCount;
  127. position_t option_goalPos[1];
  128. bool isConsoleInput;
  129. clock_t starttime;
  130. int monitorCountTurn;
  131. int monitorCountToGo;
  132. public:
  133. externalData(){}
  134. position_t getPosition(){return curPos;}
  135. void setPosition(int x,int y) throw(invalidPosition){
  136. if(x<0 || x>=MAPSIZE || y<0 || y>=MAPSIZE) throw invalidPosition();
  137. curPos.x=x;
  138. curPos.y=y;
  139. }
  140. position_t get1Goal(){
  141. return option_goalPos[0];
  142. }
  143. Walls getCurWalls() throw(invalidPosition){
  144. Walls curWalls;
  145. curWalls.data=0;
  146. curWalls.f.isGoal=false;
  147. curWalls.f.isStart=false;
  148. curWalls.f.isVisited=false;
  149. curWalls.f.n=false;
  150. curWalls.f.w=false;
  151. curWalls.f.s=false;
  152. curWalls.f.e=false;
  153.  
  154. if(curPos.y <0 || curPos.y>=MAPSIZE || curPos.x<0 || curPos.x>=MAPSIZE) throw invalidPosition();
  155. if(curPos.y<=0 || extData.u.rows[curPos.y-1].walls[curPos.x][0] == '-')
  156. curWalls.f.n=true;
  157. else curWalls.f.n=false;
  158. if(extData.u.rows[curPos.y ].cols [curPos.x][2] == '|')
  159. curWalls.f.w=true;
  160. else curWalls.f.w=false;
  161. if(extData.u.rows[curPos.y ].walls[curPos.x][0] == '-')
  162. curWalls.f.s=true;
  163. else curWalls.f.s=false;
  164. if(curPos.x<=0 || extData.u.rows[curPos.y].cols [curPos.x-1][2] == '|')
  165. curWalls.f.e=true;
  166. else curWalls.f.e=false;
  167. if(extData.u.rows[curPos.y].cols [curPos.x][0] == 'G' ||
  168. extData.u.rows[curPos.y].cols [curPos.x][0] == 'g')
  169. curWalls.f.isGoal=true;
  170. else {
  171. curWalls.f.isGoal=false;
  172. if(extData.u.rows[curPos.y].cols[curPos.x][0]=='^' ||
  173. extData.u.rows[curPos.y].cols[curPos.x][1]=='>' ||
  174. extData.u.rows[curPos.y].cols[curPos.x][1]=='v' ||
  175. extData.u.rows[curPos.y].cols[curPos.x][0]=='<')
  176. curWalls.f.isStart=true;
  177. else curWalls.f.isStart=false;
  178. }
  179. return curWalls;
  180. }
  181. void setDir(mdir_t newDir) throw(invalidPosition){
  182. if(curPos.y <0 || curPos.y>=MAPSIZE || curPos.x<0 || curPos.x>=MAPSIZE) throw invalidPosition();
  183. if(newDir==n)
  184. if(extData.u.rows[curPos.y-1].walls[curPos.x ][0]!='-'){
  185. extData.u.rows[curPos.y-1].walls[curPos.x ][0]='^';
  186. } else throw invalidToGo();
  187. else if(newDir==w)
  188. if(extData.u.rows[curPos.y ].cols [curPos.x ][2]!='|') {
  189. if(extData.u.rows[curPos.y ].cols [curPos.x ][2]==' ') extData.u.rows[curPos.y ].cols [curPos.x ][2]='>';
  190. else if(extData.u.rows[curPos.y ].cols [curPos.x ][2]=='<') extData.u.rows[curPos.y ].cols [curPos.x ][2]='=';
  191. else;
  192. } else throw invalidToGo();
  193. else if(newDir==s)
  194. if( extData.u.rows[curPos.y ].walls[curPos.x ][1]!='-') {
  195. extData.u.rows[curPos.y ].walls[curPos.x ][1]='v';
  196. } else throw invalidToGo();
  197. else if(newDir==e)
  198. if(extData.u.rows[curPos.y ].cols [curPos.x-1][2]!='|'){
  199. if(extData.u.rows[curPos.y ].cols [curPos.x-1][2]==' ') extData.u.rows[curPos.y ].cols [curPos.x-1][2]='<';
  200. else if(extData.u.rows[curPos.y ].cols [curPos.x-1][2]=='>') extData.u.rows[curPos.y ].cols [curPos.x-1][2]='~';
  201. else ;
  202. } else throw invalidToGo();
  203. monitorCountTurn += (curDir-newDir)>0 ? (curDir-newDir):(newDir-curDir);
  204. curDir=newDir;
  205. };
  206. mdir_t getDir(){return curDir;};
  207.  
  208. void displayMap() throw(extBreak){
  209. if(! isConsoleInput){
  210. cout<<"\x1b[2J";
  211. system("cls");
  212. }
  213.  
  214. cout<<extData.title1<<endl;
  215. cout<<extData.header1<<endl;
  216. for(int i=0;i<MAPDISPLAYSIZEy;i++){
  217. cout<<extData.u.displayLines[i]<<endl;
  218. }
  219. clock_t currentTime=clock();
  220. cout<<" 経過時刻:"<<(currentTime-starttime)<<"ミリ秒\t";
  221.  
  222. cout<<" position="<<curPos
  223. <<" dir="<<curDir
  224. <<endl;
  225. cout<<"移動量="<<monitorCountToGo<<"マス\t";
  226. cout<<"回転量="<<monitorCountTurn<<"折れ\t";
  227. cout<<flush;
  228. #ifdef _CRT_NONSTDC_DEPRECATE
  229. if(! isConsoleInput){
  230. int keyCode1;
  231. if(_kbhit()) {
  232. keyCode1= _getch();
  233. if(keyCode1==4) throw extBreak();
  234. }
  235. }
  236. #endif
  237. }
  238. #define strNcpyKeepTail(to,from) {unsigned char * toPtr=(unsigned char *)(&(to));unsigned char *fromPtr=(unsigned char *)(&(from));for(int i=0;i<sizeof(to)&& (*(fromPtr)>=' ');i++,toPtr++,fromPtr++)*toPtr=*fromPtr;}
  239. int loadData(std::istream &fp,bool currentIsConsoleInput){
  240. int retCount= 0;
  241. {
  242. const static displayString_t displayString0=
  243. " Title \0\0"
  244. "+00+01+02+03+04+05+06+07+08+09+10+11+12+13+14+15+\0\0"
  245. "0 | | | | | | | | | | | | | | | |\0\0"
  246. "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\0\0"
  247. "1 | | | | | | | | | | | | | | | |\0\0"
  248. "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\0\0"
  249. "2 | | | | | | | | | | | | | | | |\0\0"
  250. "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\0\0"
  251. "3 | | | | | | | | | | | | | | | |\0\0"
  252. "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\0\0"
  253. "4 | | | | | | | | | | | | | | | |\0\0"
  254. "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\0\0"
  255. "5 | | | | | | | | | | | | | | | |\0\0"
  256. "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\0\0"
  257. "6 | | | | | | | | | | | | | | | |\0\0"
  258. "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\0\0"
  259. "7 | | | | | | | | | | | | | | | |\0\0"
  260. "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\0\0"
  261. "8 | | | | | | | | | | | | | | | |\0\0"
  262. "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\0\0"
  263. "9 | | | | | | | | | | | | | | | |\0\0"
  264. "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\0\0"
  265. "a | | | | | | | | | | | | | | | |\0\0"
  266. "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\0\0"
  267. "b | | | | | | | | | | | | | | | |\0\0"
  268. "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\0\0"
  269. "c | | | | | | | | | | | | | | | |\0\0"
  270. "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\0\0"
  271. "d | | | | | | | | | | | | | | | |\0\0"
  272. "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\0\0"
  273. "e | | | | | | | | | | | | | | | |\0\0"
  274. "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\0\0"
  275. "f | | | | | | | | | | | | | | | |\0\0"
  276. "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\0\0"
  277. ;
  278. isConsoleInput=currentIsConsoleInput;
  279. displayString_t displayString1;
  280. memcpy((void *)&extData,displayString0,sizeof(extData));
  281.  
  282. fp.getline(displayString1,sizeof(displayString1));
  283. strNcpyKeepTail(extData.title1,displayString1);
  284. cout<<(char *)&(displayString1)<<endl;
  285.  
  286. fp.getline(displayString1,sizeof(displayString1));
  287. //memcpy(void *)&(extData.header1),displayString1,sizeof(extData.header1));//skip header line
  288. for(int i=0;i<MAPSIZE;i++){
  289. fp.getline(displayString1,sizeof(displayString1));
  290. strNcpyKeepTail(extData.u.rows[i].cols,(displayString1[1]));
  291.  
  292. fp.getline(displayString1,sizeof(displayString1));
  293. strNcpyKeepTail(extData.u.rows[i].walls,(displayString1[1]));
  294. }
  295.  
  296. }
  297. option_GoalsCount=0;
  298. for(int y=0;y<MAPSIZE;y++)
  299. for(int x=0;x<MAPSIZE;x++){
  300. if(extData.u.rows[y].cols[x][2]==' ' || extData.u.rows[y].cols[x][2]=='|');
  301. else {
  302. cout<<"invalid maizu | wall at "<<x<<","<<y<<":"<< extData.u.rows[y].cols[x][2]<<" "<< endl;
  303. retCount --;
  304. }
  305. if(memcmp(extData.u.rows[y].walls[x]," ",2)==0);
  306. else if(memcmp(extData.u.rows[y].walls[x],"--",2)==0);
  307. else {
  308. cout<<"invalid maizu v wall at "<<x<<","<<y<<":"<< extData.u.rows[y].walls[x][0]<<extData.u.rows[y].walls[x][1]<<" "<< endl;
  309. retCount --;
  310. }
  311. if(extData.u.rows[y].cols[x][0]=='G'){
  312. option_goalPos[option_GoalsCount].x=x;
  313. option_goalPos[option_GoalsCount].y=y;
  314. option_GoalsCount++;
  315. }//
  316. else if(extData.u.rows[y].cols[x][0]=='g'){option_GoalsCount++;} //hidden goal
  317. else if(extData.u.rows[y].cols[x][0]!=' '|| extData.u.rows[y].cols[x][1]!=' '){
  318. if(memcmp(extData.u.rows[y].cols[x],"^ ",2)==0){setPosition(x,y);setDir(n);}
  319. else if(memcmp(extData.u.rows[y].cols[x],"->",2)==0){setPosition(x,y);setDir(w);}
  320. else if(memcmp(extData.u.rows[y].cols[x]," v",2)==0){setPosition(x,y);setDir(s);}
  321. else if(memcmp(extData.u.rows[y].cols[x],"<-",2)==0){setPosition(x,y);setDir(e);}
  322. else {
  323. cout<<"invalid maizu cols at "<<x<<","<<y<<":"<<extData.u.rows[y].cols[x][0]<<extData.u.rows[y].cols[x][1]<<" "<<endl;
  324. retCount --;
  325. }
  326. }
  327. }
  328. cout<<"迷図は読みました。ゴールの数は"<<option_GoalsCount << "個。";
  329. monitorCountTurn=0;
  330. monitorCountToGo=0;
  331. starttime=clock();
  332. cout<<" 時刻:"<<starttime<<endl;
  333. if(retCount >=0) return option_GoalsCount;
  334. else return retCount;
  335. }
  336. void gotoMDir(mdir_t nextDir){
  337. Walls postWalls=getCurWalls();
  338. setDir(nextDir);
  339. if(nextDir== n)
  340. if(postWalls.f.n==false)setPosition(curPos.x,curPos.y-1);
  341. else throw invalidToGo();
  342. else if(nextDir== w)
  343. if(postWalls.f.w==false)setPosition(curPos.x+1,curPos.y);
  344. else throw invalidToGo();
  345. else if(nextDir== s)
  346. if(postWalls.f.s==false)setPosition(curPos.x,curPos.y+1);
  347. else throw invalidToGo();
  348. else if(nextDir== e)
  349. if(postWalls.f.e==false)setPosition(curPos.x-1,curPos.y);
  350. else throw invalidToGo();
  351. else;
  352. monitorCountToGo++;
  353. }
  354. bool gotoRDirBasic(rCMD_t next1CMD){
  355. cout<<next1CMD; //for debug print
  356. mdir_t nextMDir;
  357. int it;
  358. nextMDir=(mdir_t)((getDir()+(next1CMD.u.f.rDirHi))& 0x3);
  359. try{
  360. for(it=0;it<next1CMD.u.f.stepCount;it++) {
  361. gotoMDir(nextMDir);
  362. cout<<nextMDir;
  363. }
  364. return true;
  365. } catch(invalidToGo e) {//壁に衝突発生
  366. cout<<curDir; //for debug print
  367. cout<<curPos;
  368. cout<<nextMDir<<" Breaked "<<endl; //for debug print!!
  369. //throw invalidToGo();
  370. return false;
  371. }
  372. }
  373. int getGoalCount(){
  374. return option_GoalsCount;
  375. }
  376.  
  377. };
  378. #define MAXCOST (MAPSIZE*MAPSIZE+MAPSIZE*4)
  379. typedef struct {
  380. struct {
  381. unsigned int isVisited:1;
  382. unsigned int isGoal:1;
  383. //unsigned int isStart:1;
  384. unsigned int wall_n:1;
  385. unsigned int wall_e:1;
  386. unsigned int dir:4;
  387. /*7 bit padding*/
  388. unsigned int cost;
  389. } map[MAPSIZE+1][MAPSIZE];
  390. } inData_t;
  391. template <class T,size_t BufferSize>
  392. class RingBufferdQueue {
  393. T _Data[BufferSize];//リングバッファ
  394. int queueTop;
  395. int queueTail;
  396. int queueCount;
  397. public:
  398. RingBufferdQueue(){
  399. clear();
  400. }
  401. void clear(){
  402. queueTop=0; //pull point
  403. queueTail=0; //push point,ready to store
  404. queueCount=0;
  405. }
  406. bool isEmpty(){return queueTop==queueTail;}
  407. int count(){return queueCount;}
  408. void push(T newData){
  409. if(queueCount<BufferSize){
  410. _Data[queueTail]=newData;
  411. queueTail++;
  412. if(queueTail==BufferSize) queueTail=0;
  413. queueCount++;
  414. } else throw invalidQue();
  415. }
  416. void pushBack(T newData){
  417. if(queueCount<BufferSize){
  418. if(queueTop>0) queueTop--;
  419. else queueTop=BufferSize-1;
  420. _Data[queueTop]=newData;
  421. queueCount++;
  422. } else throw invalidQue();
  423. }
  424. T pull(){
  425. T newData;
  426. if(queueCount>0){
  427. queueCount--;
  428. newData=_Data[queueTop];
  429. queueTop++;
  430. if(queueTop==BufferSize) queueTop=0;
  431. } else throw invalidQue();
  432. return newData;
  433. }
  434. };
  435. typedef RingBufferdQueue<position_t,MAPSIZE*4> searchQueue;
  436. typedef RingBufferdQueue<mdir_t,MAPSIZE*MAPSIZE> mDirQueue;
  437. typedef RingBufferdQueue<rCMD_t,MAPSIZE*MAPSIZE> rDirQueue;
  438. class innerStatus{
  439. inData_t inData;
  440. position_t curPos,startPos;
  441. mdir_t curDir,startDir;
  442. bool findedGoal;
  443. searchQueue *searchPosionPtr;
  444. public:
  445. innerStatus(){
  446. restMap();
  447. findedGoal=false;
  448. }
  449. void restMap(){
  450. for(int y=0;y<MAPSIZE;y++) {
  451. for(int x=0;x<MAPSIZE;x++){
  452. inData.map[y][x].isVisited=0;
  453. inData.map[y][x].isGoal=0;
  454. inData.map[y][x].wall_n=0;
  455. inData.map[y][x].wall_e=0;
  456. inData.map[y][x].cost=MAXCOST;
  457. }
  458. inData.map[y][0].wall_e=1;
  459. }
  460. for(int x=0;x<MAPSIZE;x++){
  461. inData.map[0][x].wall_n=1;
  462. inData.map[MAPSIZE][x].wall_n=1;
  463. }
  464. }
  465. //void setPosition(position_t newPos){curPos=newPos;}
  466. void setPosition(int x,int y){
  467. curPos.x=x;
  468. curPos.y=y;
  469. inData.map[y][x].cost=0;
  470. }
  471. void set1Goal(int x,int y){
  472. inData.map[y][x].isGoal=1;
  473. //inData.map[y][x].isVisited=1; 複数ゴール対応のため、visitedは設定してはならない
  474. findedGoal=true;
  475. }
  476. void set1Start(position_t newPos,mdir_t newDir){
  477. startPos=newPos;
  478. startDir=newDir;
  479. inData.map[startPos.y][startPos.x].isVisited=1;
  480. }
  481. void setDir(mdir_t newDir){curDir=newDir;};
  482. mdir_t getDir(){return curDir;};
  483. Walls getCurWalls(){
  484. Walls curWalls;
  485. curWalls.data=0;
  486. curWalls.f.n=(inData.map[curPos.y ][curPos.x ].wall_n)?1:0;
  487. curWalls.f.w=(inData.map[curPos.y ][curPos.x+1].wall_e)?1:0;
  488. curWalls.f.s=(inData.map[curPos.y+1][curPos.x ].wall_n)?1:0;
  489. curWalls.f.e=(inData.map[curPos.y ][curPos.x ].wall_e)?1:0;
  490. curWalls.f.isGoal=(inData.map[curPos.y][curPos.x].isGoal)?1:0;
  491. curWalls.f.isVisited=inData.map[curPos.y][curPos.x].isVisited?1:0;
  492. curWalls.f.isStart=(curPos.x==startPos.x && curPos.y==startPos.y )?1:0;
  493. return curWalls;
  494. }
  495. bool setCurWalls(Walls newCurWalls){
  496. Walls preWalls=getCurWalls();
  497. inData.map[curPos.y ][curPos.x ].wall_n=(newCurWalls.f.n)?1:0;
  498. inData.map[curPos.y ][curPos.x+1].wall_e=(newCurWalls.f.w)?1:0;
  499. inData.map[curPos.y+1][curPos.x ].wall_n=(newCurWalls.f.s)?1:0;
  500. inData.map[curPos.y ][curPos.x ].wall_e=(newCurWalls.f.e)?1:0;
  501. if(newCurWalls.f.isGoal) set1Goal(curPos.x,curPos.y);
  502. inData.map[curPos.y ][curPos.x ].isVisited=1;
  503. Walls postWalls=getCurWalls();
  504. if(preWalls == postWalls)
  505. return false;
  506. else return true;
  507. }
  508. //思考ルーチン
  509. inline bool updatesCosts(int tempPosX,int tempPosY){
  510. bool abletoMove=false;
  511. #define Let_costOfDiff(nextDir,nextXdiff,nextYdiff) {\
  512. int dirDiff=((nextDir - inData.map[tempPosY][tempPosX].dir) & 3);\
  513. int costDiff=(dirDiff==0)?2:((dirDiff==2)?6:4); \
  514. unsigned int nextCost=inData.map[tempPosY][tempPosX].cost+costDiff; \
  515. position_t nextPos; \
  516. nextPos.x=tempPosX+(nextXdiff); \
  517. nextPos.y=tempPosY+(nextYdiff); \
  518. if( inData.map[nextPos.y][nextPos.x].cost>nextCost){ \
  519. inData.map[nextPos.y][nextPos.x].cost=nextCost; \
  520. inData.map[nextPos.y][nextPos.x].dir=nextDir; \
  521. abletoMove=true; \
  522. searchPosionPtr->push(nextPos); \
  523. } else ; \
  524. }
  525. if(inData.map[tempPosY][tempPosX].cost<MAXCOST){ //インメモリで移動中のセルから隣接セルへの移動コストを計算
  526. if((tempPosY-1)>=0 && inData.map[tempPosY][tempPosX].wall_n==0) { //北進可能
  527. Let_costOfDiff(n,0,-1); //北進の移動コスト計算
  528. } else ;
  529. if((tempPosX+1)<MAPSIZE && inData.map[tempPosY][tempPosX+1].wall_e==0) { //東進可能
  530. Let_costOfDiff(w,1,0); //東進の移動コスト計算
  531. } else ;
  532. if((tempPosY+1)<MAPSIZE && inData.map[tempPosY+1][tempPosX].wall_n==0) { //南進可能
  533. Let_costOfDiff(s,0,1); //南進の移動コスト計算
  534. } else ;
  535. if((tempPosX-1)>=0 && inData.map[tempPosY][tempPosX].wall_e==0) { //西進可能
  536. Let_costOfDiff(e,-1,0); //西進の移動コスト計算
  537. } else ;
  538. } else;
  539. return abletoMove;
  540. }
  541. inline bool isReached(int x,int y,bool toGoal){
  542. return (((! findedGoal) && (inData.map[y][x].isVisited==0 /*未通過セル*/) )
  543. ||( toGoal && inData.map[y][x].isGoal==1 /*ゴール*/)
  544. ||((!toGoal)&& x==startPos.x && y==startPos.y ));
  545. }
  546. void getNextrDirList(rDirQueue & rDirLIst,bool toGoal){
  547. for(int y=0;y<MAPSIZE;y++)
  548. for(int x=0;x<MAPSIZE;x++)
  549. inData.map[y][x].cost=MAXCOST;
  550. position_t tempGoalPos;
  551. {
  552. searchQueue localsearchQueue;
  553. searchPosionPtr=&localsearchQueue;
  554. searchPosionPtr->clear();
  555. searchPosionPtr->push(curPos); ///隣接セルのコスト更新を予約
  556.  
  557. inData.map[curPos.y ][curPos.x].cost=0; //カレント位置からの移動コストを計算
  558. inData.map[curPos.y ][curPos.x].dir=curDir;
  559. do {
  560. tempGoalPos=searchPosionPtr->pull();//横幅優先探索のキューから、評価対象セルを取り出す
  561. updatesCosts(tempGoalPos.x,tempGoalPos.y); //当該セルのコストを更新し、壁が挟まっていない隣接セルのコスト更新を予約
  562. if(isReached(tempGoalPos.x,tempGoalPos.y,toGoal)) break;//目標セルに到着したら、中断
  563. } while(! searchPosionPtr->isEmpty());
  564. searchPosionPtr=NULL;
  565. }
  566.  
  567. //ゴールから起点まで、逆順に最短経路をたどる
  568. {
  569. mDirQueue mDirLIst;
  570. mDirLIst.clear();
  571. mdir back2Dir;
  572. int visitedLength=0;
  573. do{
  574. back2Dir=(mdir)inData.map[tempGoalPos.y][tempGoalPos.x].dir;
  575. mDirLIst.pushBack(back2Dir);
  576. if(back2Dir==n){tempGoalPos.y +=1;}
  577. if(back2Dir==w){tempGoalPos.x -=1;}
  578. if(back2Dir==s){tempGoalPos.y -=1;}
  579. if(back2Dir==e){tempGoalPos.x +=1;}
  580. if(tempGoalPos.y<0 || MAPSIZE<=tempGoalPos.y || tempGoalPos.x<0 || MAPSIZE<= tempGoalPos.x) throw invalidPosition();
  581. if(inData.map[tempGoalPos.y][tempGoalPos.x].isVisited>0)
  582. visitedLength++;
  583. else visitedLength=0;
  584. } while(tempGoalPos.x != curPos.x || curPos.y !=tempGoalPos.y);
  585.  
  586. ///!!!
  587. {//絶対方向から相対方向のコマンドに変換
  588. mdir preMDir,postMDir;
  589. rCMD_t curRCmd;
  590. rDirLIst.clear();
  591. int countofDirect=mDirLIst.count();
  592. preMDir=getDir();
  593. for(int i=0;i<countofDirect;i++){
  594. postMDir=mDirLIst.pull();
  595. curRCmd.u.f.rDirHi=(postMDir-preMDir);
  596. curRCmd.u.f.rDirLo=0;
  597. curRCmd.u.f.stepCount=1;
  598. curRCmd.u.f.detailStep=0;
  599. rDirLIst.push(curRCmd);
  600. preMDir=postMDir;
  601. }
  602. }
  603. if(visitedLength>3){
  604. rCMD_t curRCmd,nextRCMD;
  605. int countofDirect=rDirLIst.count();
  606. if(visitedLength>(countofDirect))
  607. throw extException();
  608. curRCmd=rDirLIst.pull();
  609. for(int i=1;i<visitedLength;i++){
  610. nextRCMD=rDirLIst.pull();
  611. if(curRCmd.u.v.rDir==Forwards && nextRCMD.u.v.rDir==Forwards){//前進加速向けの最適化
  612. curRCmd.u.v.Distance +=nextRCMD.u.v.Distance;
  613. }
  614. else {
  615. rDirLIst.push(curRCmd);
  616. curRCmd=nextRCMD;
  617. }
  618. }
  619. rDirLIst.push(curRCmd);
  620. for(int i=visitedLength;i<countofDirect;i++){
  621. rDirLIst.push(rDirLIst.pull());
  622. }
  623. }
  624. }
  625.  
  626. }
  627. };
  628.  
  629. inline bool try1Pass(externalData &extData,innerStatus &innData,bool toGoal){
  630. bool MoreSearch=false;
  631. Walls CurWalls;
  632. do {
  633. position_t curPosition=extData.getPosition();
  634. innData.setPosition(curPosition.x,curPosition.y);
  635. mdir_t curDir=extData.getDir();
  636. innData.setDir(curDir);
  637. CurWalls=extData.getCurWalls();
  638. innData.setCurWalls(CurWalls);
  639. bool cellStatusChanged=false;
  640.  
  641. cout<<curDir<<curPosition; //for debug:現在位置表示
  642. rDirQueue rDirLIst;
  643. innData.getNextrDirList(rDirLIst,toGoal); //探索結果による最適経路を得る
  644. int countofDirect=rDirLIst.count();
  645. for(int i=0;i<countofDirect && (! cellStatusChanged);i++){
  646. if(!extData.gotoRDirBasic(rDirLIst.pull())) break; //最寄の未通過セルまたはゴールに向かう、第1歩に物理的に移動。
  647. position_t curPosition=extData.getPosition();
  648. curDir=extData.getDir();
  649. //cout<<curDir; //for debug print
  650. // cout<<curPosition;
  651. innData.setPosition(curPosition.x,curPosition.y);
  652. innData.setDir(curDir);
  653. CurWalls=extData.getCurWalls();
  654. cellStatusChanged=innData.setCurWalls(CurWalls);
  655. }
  656. cout<<endl; //for debug print
  657. if(cellStatusChanged)
  658. MoreSearch=true;
  659. } while(!((toGoal && CurWalls.f.isGoal) || ((!toGoal) && CurWalls.f.isStart )));
  660. return MoreSearch;
  661. }
  662. void try1Maze(externalData &extData)
  663. {
  664. innerStatus innData=innerStatus();
  665. position_t startPos=extData.getPosition();
  666. mdir_t startDir=extData.getDir();
  667. innData.set1Start(startPos,startDir);
  668. if(extData.getGoalCount()==1){//
  669. position_t goalpos=extData.get1Goal();
  670. innData.set1Goal(goalpos.x,goalpos.y);
  671. }
  672. int serchCount;
  673. try {
  674. bool MoreSearch;
  675. for(serchCount=1;serchCount<15;serchCount++){//探索モードの繰り返し
  676. try {
  677. extData.setPosition(startPos.x,startPos.y);
  678. extData.setDir(startDir);
  679. MoreSearch=try1Pass(extData,innData,true);//開始始点からgoalに向かう
  680. extData.displayMap();
  681. cout<<endl<<("!!! from start to goal reacheed!!!")<<endl;
  682. //todo:ゴールからスタートに向かう連続探索を行うか否か? NO:ゴールに向かう最短ルートに含まれない袋小路に入るため非効率。 オペレータ介入時間の短縮が必要。YES:10回分の情報を5往復で採取できる。
  683. MoreSearch=try1Pass(extData,innData,false);//現在値=goal からstartに戻る
  684. extData.displayMap();
  685. cout<<endl<<("!!! from goal to start reacheed!!!");
  686. } catch (extBreak e) {
  687. cout<<endl<<("!!! breaked !!!")<<endl;
  688. }
  689. if(MoreSearch) {
  690. cout<<serchCount<<"回探索したが、探索が必要 "<<endl;
  691. } else {
  692. cout<<serchCount<<"回の探索で、もう探索は不要"<<endl;
  693. break;
  694. }
  695. }
  696. } catch (extException e) {
  697. cout<<serchCount<<"予期しない中断!!"<<endl;
  698. }
  699. }
  700. int main(int argc, char* argv[])
  701. {
  702. {
  703. externalData extData;
  704. std::ifstream infs;
  705. std::istream *fp;
  706. if(argc>1){
  707. infs.open(argv[1]);
  708. fp=&infs;
  709. } else fp=&(std::cin);
  710. while(!(fp->eof())){
  711. if(extData.loadData(*fp,(fp==&(std::cin)))>0){
  712. extData.displayMap();
  713. try1Maze(extData);
  714. }
  715. }
  716. }
  717. return 0;
  718. }
Success #stdin #stdout 0s 3364KB
stdin
Title=micromouse 30th classic stage 15131
+00+01+02+03+04+05+06+07+08+09+10+11+12+13+14+15+
0                                               |
+--+--+--+  +--+  +--+--+  +--+--+--+  +--+--+  +
1     |     |  |        |  |  |  |  |        |  |
+--+--+  +  +  +  +  +  +--+--+  +  +--+--+  +  +
2        |  |  |  |  |     |     |        |  |  |
+  +  +--+--+  +--+  +--+  +  +  +--+--+  +  +  +
3  |        |  |     |     |  |           |  |  |
+--+--+--+  +  +  +--+  +--+  +--+--+--+  +  +  +
4  |        |  |     |  |     |  |  |  |        |
+  +--+  +--+--+--+  +  +--+  +  +  +--+--+--+  +
5  |     |        |     |  |  |  |        |  |  |
+  +--+  +  +--+  +--+--+  +  +--+--+  +  +  +  +
6        |  |  |  |     |  |  |  |     |  |  |  |
+--+--+  +  +  +  +  +--+--+  +--+  +--+  +  +  +
7        |  |  |  |  |     |  |        |  |     |
+  +  +--+  +--+  +  +  +  +  +--+--+  +  +--+  +
8  |  |        |     |   G    |  |     |        |
+  +  +  +--+  +  +--+--+--+--+--+  +  +--+--+  +
9  |  |  |  |  |  |  |  |     |     |  |  |  |  |
+  +--+  +  +  +  +--+--+  +  +--+--+  +--+--+  +
a  |     |  |  |  |  |     |  |     |     |  |  |
+  +  +--+--+  +--+  +  +--+  +--+--+--+  +--+  +
b  |  |  |  |     |  |  |  |                    |
+  +  +  +  +--+  +  +  +--+  +--+--+  +--+--+  +
c     |  |  |  |     |     |           |  |     |
+  +  +--+  +--+--+  +--+  +--+--+--+--+  +  +  +
d  |  |        |  |           |  |        |  |  |
+  +  +  +--+  +--+  +--+--+--+  +--+--+--+  +  +
e  |     |           |                       |  |
+  +--+--+--+--+--+--+  +--+--+--+  +--+--+--+  +
f^ |  |                 |        |              |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
stdout
Title=micromouse 30th classic stage 15131
迷図は読みました。ゴールの数は1個。 時刻:0
Title=micromouse 30th classic stage 15131        
+00+01+02+03+04+05+06+07+08+09+10+11+12+13+14+15+
0                                               |
+--+--+--+  +--+  +--+--+  +--+--+--+  +--+--+  +
1     |     |  |        |  |  |  |  |        |  |
+--+--+  +  +  +  +  +  +--+--+  +  +--+--+  +  +
2        |  |  |  |  |     |     |        |  |  |
+  +  +--+--+  +--+  +--+  +  +  +--+--+  +  +  +
3  |        |  |     |     |  |           |  |  |
+--+--+--+  +  +  +--+  +--+  +--+--+--+  +  +  +
4  |        |  |     |  |     |  |  |  |        |
+  +--+  +--+--+--+  +  +--+  +  +  +--+--+--+  +
5  |     |        |     |  |  |  |        |  |  |
+  +--+  +  +--+  +--+--+  +  +--+--+  +  +  +  +
6        |  |  |  |     |  |  |  |     |  |  |  |
+--+--+  +  +  +  +  +--+--+  +--+  +--+  +  +  +
7        |  |  |  |  |     |  |        |  |     |
+  +  +--+  +--+  +  +  +  +  +--+--+  +  +--+  +
8  |  |        |     |   G    |  |     |        |
+  +  +  +--+  +  +--+--+--+--+--+  +  +--+--+  +
9  |  |  |  |  |  |  |  |     |     |  |  |  |  |
+  +--+  +  +  +  +--+--+  +  +--+--+  +--+--+  +
a  |     |  |  |  |  |     |  |     |     |  |  |
+  +  +--+--+  +--+  +  +--+  +--+--+--+  +--+  +
b  |  |  |  |     |  |  |  |                    |
+  +  +  +  +--+  +  +  +--+  +--+--+  +--+--+  +
c     |  |  |  |     |     |           |  |     |
+  +  +--+  +--+--+  +--+  +--+--+--+--+  +  +  +
d  |  |        |  |           |  |        |  |  |
+  +  +  +--+  +--+  +--+--+--+  +--+--+--+  +  +
e  |     |           |                       |  |
+^ +--+--+--+--+--+--+  +--+--+--+  +--+--+--+  +
f^ |  |                 |        |              |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 経過時刻:0ミリ秒	 position=(0,15) dir=n
移動量=0マス	回転量=0折れ	n(0,15)(F,1.0)n
n(0,14)(F,1.0)n
n(0,13)(F,1.0)n(F,1.0)n
n(0,11)(F,1.0)n
n(0,10)(F,1.0)n
n(0,9)(F,1.0)n
n(0,8)(F,1.0)n
n(0,7)(R,1.0)w
w(1,7)(F,1.0)w
w(2,7)(L,1.0)n
n(2,6)(F,1.0)n
n(2,5)(F,1.0)n
n(2,4)(R,1.0)w
w(3,4)(L,1.0)n
n(3,3)(L,1.0)e
e(2,3)(F,1.0)e
e(1,3)(R,1.0)n
n(1,2)(R,1.0)w
w(2,2)(L,1.0)n
n(2,1)(R,1.0)w
w(3,1)(R,1.0)s
s(3,2)(Bak,1.0)n(F,1.0)n(R,1.0)w
w(4,0)(F,1.0)w(F,1.0)w
w(6,0)(F,1.0)w
w(7,0)(F,1.0)w(R,1.0)s
s(8,1)(Bak,1.0)n(R,1.0)w
w(9,0)(F,1.0)w
w(10,0)(F,1.0)w
w(11,0)(F,1.0)w(R,1.0)s
s(12,1)(L,1.0)w
w(13,1)(F,1.0)w
w(14,1)(R,1.0)s
s(14,2)(F,1.0)s
s(14,3)(F,1.0)s
s(14,4)(R,1.0)e
e(13,4)(R,1.0)n(L,1.0)e
e(12,3)(F,1.0)e
e(11,3)(F,1.0)e
e(10,3)(R,1.0)n
n(10,2)(L,1.0)e
e(9,2)(L,1.0)s
s(9,3)(F,1.0)s
s(9,4)(F,1.0)s
s(9,5)(F,1.0)s
s(9,6)(F,1.0)s
s(9,7)(F,1.0)s
s(9,8)(R,1.0)e
Title=micromouse 30th classic stage 15131        
+00+01+02+03+04+05+06+07+08+09+10+11+12+13+14+15+
0           >  >  >  >  >  >  >  >  >           |
+--+--+--+^ +--+  +--+--+^v+--+--+--+ v+--+--+  +
1     |  >  |  |        |  |  |  |  |  >  >  |  |
+--+--+^ +^v+  +  +  +  +--+--+  +  +--+--+ v+  +
2     >  |  |  |  |  |     |  <  |        |  |  |
+  +^ +--+--+  +--+  +--+  + v+^ +--+--+  + v+  +
3  |  <  <  |  |     |     |  |  <  <  <  |  |  |
+--+--+--+^ +  +  +--+  +--+ v+--+--+--+^ + v+  +
4  |     >  |  |     |  |     |  |  |  |  <     |
+  +--+^ +--+--+--+  +  +--+ v+  +  +--+--+--+  +
5  |     |        |     |  |  |  |        |  |  |
+  +--+^ +  +--+  +--+--+  + v+--+--+  +  +  +  +
6        |  |  |  |     |  |  |  |     |  |  |  |
+--+--+^ +  +  +  +  +--+--+ v+--+  +--+  +  +  +
7  >  >  |  |  |  |  |     |  |        |  |     |
+^ +  +--+  +--+  +  +  +  + v+--+--+  +  +--+  +
8  |  |        |     |   G <  |  |     |        |
+^ +  +  +--+  +  +--+--+--+--+--+  +  +--+--+  +
9  |  |  |  |  |  |  |  |     |     |  |  |  |  |
+^ +--+  +  +  +  +--+--+  +  +--+--+  +--+--+  +
a  |     |  |  |  |  |     |  |     |     |  |  |
+^ +  +--+--+  +--+  +  +--+  +--+--+--+  +--+  +
b  |  |  |  |     |  |  |  |                    |
+^ +  +  +  +--+  +  +  +--+  +--+--+  +--+--+  +
c     |  |  |  |     |     |           |  |     |
+^ +  +--+  +--+--+  +--+  +--+--+--+--+  +  +  +
d  |  |        |  |           |  |        |  |  |
+^ +  +  +--+  +--+  +--+--+--+  +--+--+--+  +  +
e  |     |           |                       |  |
+^ +--+--+--+--+--+--+  +--+--+--+  +--+--+--+  +
f^ |  |                 |        |              |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 経過時刻:0ミリ秒	 position=(8,8) dir=e
移動量=55マス	回転量=39折れ	
!!! from start to goal reacheed!!!
e(8,8)(F,1.0)e
e(7,8)(R,1.0)n
n(7,7)(R,1.0)w
w(8,7)(R,1.0)s(L,1.0)w(L,1.0)n(F,3.0)nnn(L,1.0)e
e(8,4)(Bak,1.0)w(L,1.0)n(F,1.0)n(R,1.0)w(R,1.0)s(L,1.0)w(F,2.0)ww(R,1.0)s(L,1.0)w(F,1.0)w(R,1.0)s
s(15,5)(F,1.0)s
s(15,6)(F,1.0)s(F,1.0)s(F,1.0)s
s(15,9)(F,1.0)s
s(15,10)(F,1.0)s(F,1.0)s(R,1.0)e
e(14,12)(L,1.0)s
s(14,13)(F,1.0)s
s(14,14)(R,1.0)e
e(13,14)(F,1.0)e
e(12,14)(F,1.0)e
e(11,14)(F,1.0)e
e(10,14)(F,1.0)e
e(9,14)(F,1.0)e
e(8,14)(F,1.0)e
e(7,14)(L,1.0)s
s(7,15)(R,1.0)e
e(6,15)(F,1.0)e
e(5,15)(F,1.0)e
e(4,15)(F,1.0)e
e(3,15)(F,1.0)e
e(2,15)(Bak,1.0)w(F,4.0)wwww(L,1.0)n(R,1.0)w(F,2.0)ww(L,1.0)n
n(10,13)(Bak,1.0)s(L,1.0)w(F,3.0)www(L,1.0)n(F,1.0)n(R,1.0)w(L,1.0)n(L,1.0)e
e(14,11)(F,1.0)e
e(13,11)(F,1.0)e
e(12,11)(F,1.0)e
e(11,11)(F,1.0)e
e(10,11)(F,1.0)e
e(9,11)(L,1.0)s
s(9,12)(Bak,1.0)n(F,1.0)n
n(9,10)(F,1.0)n
n(9,9)(L,1.0)e
e(8,9)(L,1.0)s
s(8,10)(R,1.0)e
e(7,10)(L,1.0)s
s(7,11)(F,1.0)s
s(7,12)(L,1.0)w
w(8,12)(R,1.0)s(R,1.0)e(F,1.0)e
e(6,13)(R,1.0)n(L,1.0)e
e(5,12)(R,1.0)n
n(5,11)(L,1.0)e
e(4,11)(R,1.0)n
n(4,10)(F,1.0)n
n(4,9)(F,1.0)n
n(4,8)(L,1.0)e
e(3,8)(F,1.0)e
e(2,8)(L,1.0)s
s(2,9)(F,1.0)s
s(2,10)(R,1.0)e
e(1,10)(L,1.0)s
s(1,11)(F,1.0)s
s(1,12)(R,1.0)e(L,1.0)s(F,2.0)ss
Title=micromouse 30th classic stage 15131        
+00+01+02+03+04+05+06+07+08+09+10+11+12+13+14+15+
0           >  >  >  >  >  >  >  >  >           |
+--+--+--+^ +--+  +--+--+^v+--+--+--+ v+--+--+  +
1     |  >  |  |        |  |  |  |  |  >  >  |  |
+--+--+^ +^v+  +  +  +  +--+--+  +  +--+--+ v+  +
2     >  |  |  |  |  |     |  =  |        |  |  |
+  +^ +--+--+  +--+  +--+  +^v+^v+--+--+  + v+  +
3  |  <  <  |  |     |     |  |  =  =  =  |  |  |
+--+--+--+^ +  +  +--+  +--+^v+--+--+--+^v+ v+  +
4  |     >  |  |     |  |  =  |  |  |  |  =  >  |
+  +--+^ +--+--+--+  +  +--+^v+  +  +--+--+--+ v+
5  |     |        |     |  |  |  |        |  |  |
+  +--+^ +  +--+  +--+--+  +^v+--+--+  +  +  + v+
6        |  |  |  |     |  |  |  |     |  |  |  |
+--+--+^ +  +  +  +  +--+--+^v+--+  +--+  +  + v+
7  >  >  |  |  |  |  |  >  |  |        |  |     |
+^ +  +--+  +--+  +  +^ + v+^v+--+--+  +  +--+ v+
8  |  |  <  <  |     |  <G =  |  |     |        |
+^ +  + v+--+^ +  +--+--+--+--+--+  +  +--+--+ v+
9  |  |  |  |  |  |  |  |  <  |     |  |  |  |  |
+^ +--+ v+  +^ +  +--+--+ v+^ +--+--+  +--+--+ v+
a  |  <  |  |  |  |  |  <  |  |     |     |  |  |
+^ + v+--+--+^ +--+  + v+--+^ +--+--+--+  +--+ v+
b  |  |  |  |  <  |  |  |  |  <  <  <  <  <  <  |
+^ + v+  +  +--+^ +  + v+--+^v+--+--+  +--+--+^v+
c  <  |  |  |  |  <  |  >  |           |  |  =  |
+^v+  +--+  +--+--+^ +--+ v+--+--+--+--+  +^v+  +
d  |  |        |  |  <  <     |  |        |  |  |
+^v+  +  +--+  +--+  +--+--+--+^v+--+--+--+^v+  +
e  |     |           |  =  =  =  =  =  =  =  |  |
+^v+--+--+--+--+--+--+^v+--+--+--+  +--+--+--+  +
f^ |  |  =  =  =  =  =  |        |              |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 経過時刻:0ミリ秒	 position=(0,15) dir=s
移動量=156マス	回転量=112折れ	
!!! from goal to start reacheed!!!1回探索したが、探索が必要 
n(0,15)(F,3.0)nnn(R,1.0)w(L,1.0)n(F,1.0)n(R,1.0)w(L,1.0)n(F,1.0)n(R,1.0)w(L,1.0)n
n(3,7)(F,1.0)n
n(3,6)(F,1.0)n(R,1.0)w
w(4,5)(F,1.0)w
w(5,5)(R,1.0)s
s(5,6)(F,1.0)s
s(5,7)(F,1.0)s(L,1.0)w
w(6,8)(L,1.0)n(F,1.0)n
n(6,6)(R,1.0)w
w(7,6)(Bak,1.0)e(L,1.0)s(F,1.0)s(R,1.0)e(L,1.0)s
s(5,9)(F,1.0)s
s(5,10)(Bak,1.0)n(F,4.0)nnnn(L,1.0)e(F,1.0)e(L,1.0)s(F,2.0)ss(L,1.0)w(R,1.0)s(F,2.0)ss(L,1.0)w(R,1.0)s(L,1.0)w(R,1.0)s(L,1.0)w(F,1.0)w(L,1.0)n(L,1.0)e(R,1.0)n(F,1.0)n(R,1.0)w(L,1.0)n(R,1.0)w(R,1.0)s(F,1.0)s(L,1.0)w(F,5.0)wwwww(L,1.0)n(F,6.0)nnnnnn(L,1.0)e(F,1.0)e(R,1.0)n(L,1.0)e(F,2.0)ee(R,1.0)n(L,1.0)e(L,1.0)s(F,5.0)sssss(R,1.0)e
Title=micromouse 30th classic stage 15131        
+00+01+02+03+04+05+06+07+08+09+10+11+12+13+14+15+
0           >  >  >  >  >  >  >  >  >           |
+--+--+--+^ +--+  +--+--+^v+--+--+--+ v+--+--+  +
1     |  >  |  |        |  |  |  |  |  >  >  |  |
+--+--+^ +^v+  +  +  +  +--+--+  +  +--+--+ v+  +
2     >  |  |  |  |  |     |  =  |        |  |  |
+  +^ +--+--+  +--+  +--+  +^v+^v+--+--+  + v+  +
3  |  <  <  |  |     |     |  |  =  =  =  |  |  |
+--+--+--+^ +  +  +--+  +--+^v+--+--+--+^v+ v+  +
4  |     >  |  |     |  |  =  |  |  |  |  =  ~  |
+  +--+^ +--+--+--+  +  +--+^v+  +  +--+--+--+^v+
5  |     |  ~  ~  |     |  |  |  |        |  |  |
+  +--+^ +^v+--+^v+--+--+  +^v+--+--+  +  +  +^v+
6        |  |  |  |  ~  |  |  |  |     |  |  |  |
+--+--+^ +^v+  +^v+^v+--+--+^v+--+  +--+  +  +^v+
7  >  >  |  |  |  |  |  >  |  |        |  |     |
+^ +  +--+^v+--+^v+^v+^ + v+^v+--+--+  +  +--+^v+
8  |  |  =  =  |  ~  |  <G =  |  |     |        |
+^ +  +^v+--+^v+^v+--+--+--+--+--+  +  +--+--+^v+
9  |  |  |  |  |  |  |  |  =  |     |  |  |  |  |
+^ +--+^v+  +^v+^v+--+--+^v+^v+--+--+  +--+--+^v+
a  |  =  |  |  |  |  |  =  |  |     |     |  |  |
+^ +^v+--+--+^v+--+  +^v+--+^v+--+--+--+  +--+^v+
b  |  |  |  |  =  |  |  |  |  =  =  =  =  =  =  |
+^ +^v+  +  +--+^v+  +^v+--+^v+--+--+  +--+--+^v+
c  =  |  |  |  |  =  |  ~  |           |  |  =  |
+^v+  +--+  +--+--+^v+--+^v+--+--+--+--+  +^v+  +
d  |  |        |  |  =  =     |  |        |  |  |
+^v+  +  +--+  +--+  +--+--+--+^v+--+--+--+^v+  +
e  |     |           |  =  =  =  =  =  =  =  |  |
+^v+--+--+--+--+--+--+^v+--+--+--+  +--+--+--+  +
f^ |  |  =  =  =  =  =  |        |              |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 経過時刻:0ミリ秒	 position=(8,8) dir=e
移動量=241マス	回転量=173折れ	
!!! from start to goal reacheed!!!
e(8,8)(Bak,1.0)w(L,1.0)n(F,5.0)nnnnn(R,1.0)w(R,1.0)s(L,1.0)w(F,2.0)ww(R,1.0)s(L,1.0)w(L,1.0)n(F,2.0)nn(L,1.0)e(F,1.0)e(R,1.0)n(L,1.0)e(F,9.0)eeeeeeeee(F,1.0)e
e(1,0)(F,1.0)e
e(0,0)(Bak,1.0)w(F,2.0)ww(R,1.0)s(R,1.0)e(L,1.0)s(R,1.0)e(F,1.0)e
e(0,2)(L,1.0)s
s(0,3)(Bak,1.0)n(R,1.0)w(R,1.0)s(L,1.0)w(F,1.0)w(R,1.0)s(R,1.0)e(L,1.0)s(F,2.0)ss(R,1.0)e(F,1.0)e(L,1.0)s(F,7.0)sssssss
Title=micromouse 30th classic stage 15131        
+00+01+02+03+04+05+06+07+08+09+10+11+12+13+14+15+
0  =  =  =  ~  ~  ~  ~  ~  ~  ~  ~  ~           |
+--+--+--+^v+--+  +--+--+^v+--+--+--+^v+--+--+  +
1     |  ~  |  |        |  |  |  |  |  ~  ~  |  |
+--+--+^v+^v+  +  +  +  +--+--+  +  +--+--+^v+  +
2  =  ~  |  |  |  |  |     |  =  |        |  |  |
+^v+^v+--+--+  +--+  +--+  +^v+^v+--+--+  +^v+  +
3  |  =  =  |  |     |     |  |  =  =  =  |  |  |
+--+--+--+^v+  +  +--+  +--+^v+--+--+--+^v+^v+  +
4  |     ~  |  |     |  |  =  |  |  |  |  =  ~  |
+  +--+^v+--+--+--+  +  +--+^v+  +  +--+--+--+^v+
5  |     |  ~  ~  |     |  |  |  |        |  |  |
+  +--+^v+^v+--+^v+--+--+  +^v+--+--+  +  +  +^v+
6        |  |  |  |  ~  |  |  |  |     |  |  |  |
+--+--+^v+^v+  +^v+^v+--+--+^v+--+  +--+  +  +^v+
7  ~  ~  |  |  |  |  |  >  |  |        |  |     |
+^v+  +--+^v+--+^v+^v+^ + v+^v+--+--+  +  +--+^v+
8  |  |  =  =  |  ~  |  <G =  |  |     |        |
+^v+  +^v+--+^v+^v+--+--+--+--+--+  +  +--+--+^v+
9  |  |  |  |  |  |  |  |  =  |     |  |  |  |  |
+^v+--+^v+  +^v+^v+--+--+^v+^v+--+--+  +--+--+^v+
a  |  =  |  |  |  |  |  =  |  |     |     |  |  |
+^v+^v+--+--+^v+--+  +^v+--+^v+--+--+--+  +--+^v+
b  |  |  |  |  =  |  |  |  |  =  =  =  =  =  =  |
+^v+^v+  +  +--+^v+  +^v+--+^v+--+--+  +--+--+^v+
c  =  |  |  |  |  =  |  ~  |           |  |  =  |
+^v+  +--+  +--+--+^v+--+^v+--+--+--+--+  +^v+  +
d  |  |        |  |  =  =     |  |        |  |  |
+^v+  +  +--+  +--+  +--+--+--+^v+--+--+--+^v+  +
e  |     |           |  =  =  =  =  =  =  =  |  |
+^v+--+--+--+--+--+--+^v+--+--+--+  +--+--+--+  +
f^ |  |  =  =  =  =  =  |        |              |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 経過時刻:0ミリ秒	 position=(0,15) dir=s
移動量=302マス	回転量=208折れ	
!!! from goal to start reacheed!!!2回探索したが、探索が必要 
n(0,15)(F,8.0)nnnnnnnn(R,1.0)w(F,1.0)w(L,1.0)n(F,2.0)nn(R,1.0)w(L,1.0)n(L,1.0)e(F,1.0)e(R,1.0)n(R,1.0)w(L,1.0)n(R,1.0)w(L,1.0)n(R,1.0)w(F,8.0)wwwwwwww(R,1.0)s(L,1.0)w(F,1.0)w(R,1.0)s(F,2.0)ss(R,1.0)e(R,1.0)n(L,1.0)e(F,2.0)ee(R,1.0)n(L,1.0)e(L,1.0)s(F,5.0)sssss(R,1.0)e
Title=micromouse 30th classic stage 15131        
+00+01+02+03+04+05+06+07+08+09+10+11+12+13+14+15+
0  =  =  =  ~  ~  ~  ~  ~  ~  ~  ~  ~           |
+--+--+--+^v+--+  +--+--+^v+--+--+--+^v+--+--+  +
1     |  ~  |  |        |  |  |  |  |  ~  ~  |  |
+--+--+^v+^v+  +  +  +  +--+--+  +  +--+--+^v+  +
2  =  ~  |  |  |  |  |     |  =  |        |  |  |
+^v+^v+--+--+  +--+  +--+  +^v+^v+--+--+  +^v+  +
3  |  =  =  |  |     |     |  |  =  =  =  |  |  |
+--+--+--+^v+  +  +--+  +--+^v+--+--+--+^v+^v+  +
4  |     ~  |  |     |  |  =  |  |  |  |  =  ~  |
+  +--+^v+--+--+--+  +  +--+^v+  +  +--+--+--+^v+
5  |     |  ~  ~  |     |  |  |  |        |  |  |
+  +--+^v+^v+--+^v+--+--+  +^v+--+--+  +  +  +^v+
6        |  |  |  |  ~  |  |  |  |     |  |  |  |
+--+--+^v+^v+  +^v+^v+--+--+^v+--+  +--+  +  +^v+
7  ~  ~  |  |  |  |  |  >  |  |        |  |     |
+^v+  +--+^v+--+^v+^v+^ + v+^v+--+--+  +  +--+^v+
8  |  |  =  =  |  ~  |  <G =  |  |     |        |
+^v+  +^v+--+^v+^v+--+--+--+--+--+  +  +--+--+^v+
9  |  |  |  |  |  |  |  |  =  |     |  |  |  |  |
+^v+--+^v+  +^v+^v+--+--+^v+^v+--+--+  +--+--+^v+
a  |  =  |  |  |  |  |  =  |  |     |     |  |  |
+^v+^v+--+--+^v+--+  +^v+--+^v+--+--+--+  +--+^v+
b  |  |  |  |  =  |  |  |  |  =  =  =  =  =  =  |
+^v+^v+  +  +--+^v+  +^v+--+^v+--+--+  +--+--+^v+
c  =  |  |  |  |  =  |  ~  |           |  |  =  |
+^v+  +--+  +--+--+^v+--+^v+--+--+--+--+  +^v+  +
d  |  |        |  |  =  =     |  |        |  |  |
+^v+  +  +--+  +--+  +--+--+--+^v+--+--+--+^v+  +
e  |     |           |  =  =  =  =  =  =  =  |  |
+^v+--+--+--+--+--+--+^v+--+--+--+  +--+--+--+  +
f^ |  |  =  =  =  =  =  |        |              |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 経過時刻:0ミリ秒	 position=(8,8) dir=e
移動量=353マス	回転量=243折れ	
!!! from start to goal reacheed!!!
e(8,8)(Bak,1.0)w(L,1.0)n(F,5.0)nnnnn(R,1.0)w(R,1.0)s(L,1.0)w(F,2.0)ww(R,1.0)s(L,1.0)w(F,1.0)w(R,1.0)s(F,6.0)ssssss(R,1.0)e(F,5.0)eeeee(R,1.0)n(F,1.0)n(L,1.0)e(L,1.0)s(R,1.0)e(L,1.0)s(F,1.0)s(L,1.0)w(R,1.0)s(R,1.0)e(F,1.0)e(L,1.0)s(R,1.0)e
e(5,14)(F,1.0)e(F,1.0)e
e(3,14)(Bak,1.0)w(L,1.0)n
n(4,13)(L,1.0)e(F,1.0)e
e(2,13)(L,1.0)s(R,1.0)e
e(1,14)(R,1.0)n(F,1.0)n(L,1.0)e(L,1.0)s(F,1.0)s(F,1.0)s
Title=micromouse 30th classic stage 15131        
+00+01+02+03+04+05+06+07+08+09+10+11+12+13+14+15+
0  =  =  =  ~  ~  ~  ~  ~  ~  ~  ~  ~           |
+--+--+--+^v+--+  +--+--+^v+--+--+--+^v+--+--+  +
1     |  ~  |  |        |  |  |  |  |  ~  ~  |  |
+--+--+^v+^v+  +  +  +  +--+--+  +  +--+--+^v+  +
2  =  ~  |  |  |  |  |     |  =  |        |  |  |
+^v+^v+--+--+  +--+  +--+  +^v+^v+--+--+  +^v+  +
3  |  =  =  |  |     |     |  |  =  =  =  |  |  |
+--+--+--+^v+  +  +--+  +--+^v+--+--+--+^v+^v+  +
4  |     ~  |  |     |  |  =  |  |  |  |  =  ~  |
+  +--+^v+--+--+--+  +  +--+^v+  +  +--+--+--+^v+
5  |     |  ~  ~  |     |  |  |  |        |  |  |
+  +--+^v+^v+--+^v+--+--+  +^v+--+--+  +  +  +^v+
6        |  |  |  |  ~  |  |  |  |     |  |  |  |
+--+--+^v+^v+  +^v+^v+--+--+^v+--+  +--+  +  +^v+
7  ~  ~  |  |  |  |  |  >  |  |        |  |     |
+^v+  +--+^v+--+^v+^v+^ + v+^v+--+--+  +  +--+^v+
8  |  |  =  =  |  ~  |  <G =  |  |     |        |
+^v+  +^v+--+^v+^v+--+--+--+--+--+  +  +--+--+^v+
9  |  |  |  |  |  |  |  |  =  |     |  |  |  |  |
+^v+--+^v+  +^v+^v+--+--+^v+^v+--+--+  +--+--+^v+
a  |  =  |  |  |  |  |  =  |  |     |     |  |  |
+^v+^v+--+--+^v+--+  +^v+--+^v+--+--+--+  +--+^v+
b  |  |  |  |  =  |  |  |  |  =  =  =  =  =  =  |
+^v+^v+  +  +--+^v+  +^v+--+^v+--+--+  +--+--+^v+
c  =  |  |  |  |  =  |  ~  |           |  |  =  |
+^v+^ +--+  +--+--+^v+--+^v+--+--+--+--+  +^v+  +
d  |  |  <  <  |  |  =  =     |  |        |  |  |
+^v+^ + v+--+^ +--+ v+--+--+--+^v+--+--+--+^v+  +
e  |  <  |  =  <  <  |  =  =  =  =  =  =  =  |  |
+^v+--+--+--+--+--+--+^v+--+--+--+  +--+--+--+  +
f^ |  |  =  =  =  =  =  |        |              |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 経過時刻:0ミリ秒	 position=(0,15) dir=s
移動量=408マス	回転量=282折れ	
!!! from goal to start reacheed!!!3回探索したが、探索が必要 
n(0,15)(F,8.0)nnnnnnnn(R,1.0)w(F,1.0)w(L,1.0)n(F,2.0)nn(R,1.0)w(L,1.0)n(L,1.0)e(F,1.0)e(R,1.0)n(R,1.0)w(L,1.0)n(R,1.0)w(L,1.0)n(R,1.0)w(F,8.0)wwwwwwww(R,1.0)s(L,1.0)w(F,1.0)w(R,1.0)s(F,2.0)ss(R,1.0)e(R,1.0)n(L,1.0)e(F,2.0)ee(R,1.0)n(L,1.0)e(L,1.0)s(F,5.0)sssss(R,1.0)e
Title=micromouse 30th classic stage 15131        
+00+01+02+03+04+05+06+07+08+09+10+11+12+13+14+15+
0  =  =  =  ~  ~  ~  ~  ~  ~  ~  ~  ~           |
+--+--+--+^v+--+  +--+--+^v+--+--+--+^v+--+--+  +
1     |  ~  |  |        |  |  |  |  |  ~  ~  |  |
+--+--+^v+^v+  +  +  +  +--+--+  +  +--+--+^v+  +
2  =  ~  |  |  |  |  |     |  =  |        |  |  |
+^v+^v+--+--+  +--+  +--+  +^v+^v+--+--+  +^v+  +
3  |  =  =  |  |     |     |  |  =  =  =  |  |  |
+--+--+--+^v+  +  +--+  +--+^v+--+--+--+^v+^v+  +
4  |     ~  |  |     |  |  =  |  |  |  |  =  ~  |
+  +--+^v+--+--+--+  +  +--+^v+  +  +--+--+--+^v+
5  |     |  ~  ~  |     |  |  |  |        |  |  |
+  +--+^v+^v+--+^v+--+--+  +^v+--+--+  +  +  +^v+
6        |  |  |  |  ~  |  |  |  |     |  |  |  |
+--+--+^v+^v+  +^v+^v+--+--+^v+--+  +--+  +  +^v+
7  ~  ~  |  |  |  |  |  >  |  |        |  |     |
+^v+  +--+^v+--+^v+^v+^ + v+^v+--+--+  +  +--+^v+
8  |  |  =  =  |  ~  |  <G =  |  |     |        |
+^v+  +^v+--+^v+^v+--+--+--+--+--+  +  +--+--+^v+
9  |  |  |  |  |  |  |  |  =  |     |  |  |  |  |
+^v+--+^v+  +^v+^v+--+--+^v+^v+--+--+  +--+--+^v+
a  |  =  |  |  |  |  |  =  |  |     |     |  |  |
+^v+^v+--+--+^v+--+  +^v+--+^v+--+--+--+  +--+^v+
b  |  |  |  |  =  |  |  |  |  =  =  =  =  =  =  |
+^v+^v+  +  +--+^v+  +^v+--+^v+--+--+  +--+--+^v+
c  =  |  |  |  |  =  |  ~  |           |  |  =  |
+^v+^ +--+  +--+--+^v+--+^v+--+--+--+--+  +^v+  +
d  |  |  <  <  |  |  =  =     |  |        |  |  |
+^v+^ + v+--+^ +--+ v+--+--+--+^v+--+--+--+^v+  +
e  |  <  |  =  <  <  |  =  =  =  =  =  =  =  |  |
+^v+--+--+--+--+--+--+^v+--+--+--+  +--+--+--+  +
f^ |  |  =  =  =  =  =  |        |              |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 経過時刻:0ミリ秒	 position=(8,8) dir=e
移動量=459マス	回転量=317折れ	
!!! from start to goal reacheed!!!
e(8,8)(Bak,1.0)w(L,1.0)n(F,5.0)nnnnn(R,1.0)w(R,1.0)s(L,1.0)w(F,2.0)ww(R,1.0)s(L,1.0)w(L,1.0)n(F,2.0)nn(L,1.0)e(F,1.0)e(R,1.0)n(L,1.0)e(F,8.0)eeeeeeee(L,1.0)s(R,1.0)e(L,1.0)s(R,1.0)e(L,1.0)s(L,1.0)w(F,1.0)w(R,1.0)s(R,1.0)e(L,1.0)s(F,2.0)ss(R,1.0)e(F,1.0)e(L,1.0)s(F,7.0)sssssss
Title=micromouse 30th classic stage 15131        
+00+01+02+03+04+05+06+07+08+09+10+11+12+13+14+15+
0  =  =  =  ~  ~  ~  ~  ~  ~  ~  ~  ~           |
+--+--+--+^v+--+  +--+--+^v+--+--+--+^v+--+--+  +
1     |  ~  |  |        |  |  |  |  |  ~  ~  |  |
+--+--+^v+^v+  +  +  +  +--+--+  +  +--+--+^v+  +
2  =  ~  |  |  |  |  |     |  =  |        |  |  |
+^v+^v+--+--+  +--+  +--+  +^v+^v+--+--+  +^v+  +
3  |  =  =  |  |     |     |  |  =  =  =  |  |  |
+--+--+--+^v+  +  +--+  +--+^v+--+--+--+^v+^v+  +
4  |     ~  |  |     |  |  =  |  |  |  |  =  ~  |
+  +--+^v+--+--+--+  +  +--+^v+  +  +--+--+--+^v+
5  |     |  ~  ~  |     |  |  |  |        |  |  |
+  +--+^v+^v+--+^v+--+--+  +^v+--+--+  +  +  +^v+
6        |  |  |  |  ~  |  |  |  |     |  |  |  |
+--+--+^v+^v+  +^v+^v+--+--+^v+--+  +--+  +  +^v+
7  ~  ~  |  |  |  |  |  >  |  |        |  |     |
+^v+  +--+^v+--+^v+^v+^ + v+^v+--+--+  +  +--+^v+
8  |  |  =  =  |  ~  |  <G =  |  |     |        |
+^v+  +^v+--+^v+^v+--+--+--+--+--+  +  +--+--+^v+
9  |  |  |  |  |  |  |  |  =  |     |  |  |  |  |
+^v+--+^v+  +^v+^v+--+--+^v+^v+--+--+  +--+--+^v+
a  |  =  |  |  |  |  |  =  |  |     |     |  |  |
+^v+^v+--+--+^v+--+  +^v+--+^v+--+--+--+  +--+^v+
b  |  |  |  |  =  |  |  |  |  =  =  =  =  =  =  |
+^v+^v+  +  +--+^v+  +^v+--+^v+--+--+  +--+--+^v+
c  =  |  |  |  |  =  |  ~  |           |  |  =  |
+^v+^ +--+  +--+--+^v+--+^v+--+--+--+--+  +^v+  +
d  |  |  <  <  |  |  =  =     |  |        |  |  |
+^v+^ + v+--+^ +--+ v+--+--+--+^v+--+--+--+^v+  +
e  |  <  |  =  <  <  |  =  =  =  =  =  =  =  |  |
+^v+--+--+--+--+--+--+^v+--+--+--+  +--+--+--+  +
f^ |  |  =  =  =  =  =  |        |              |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
 経過時刻:0ミリ秒	 position=(0,15) dir=s
移動量=510マス	回転量=346折れ	
!!! from goal to start reacheed!!!4回の探索で、もう探索は不要