Index: src/solver.d ================================================================== --- src/solver.d +++ src/solver.d @@ -609,11 +609,26 @@ this.g = g.clone(); } char single_step() { - char c = think(g); + auto dm = death_move(g); + + char c = think(g, dm[0]); + if(c == 'W') { + wait_counter++; + if(dm[0].count(c) || wait_counter>=3) { + c = 'A'; + foreach(char cc; "DLRU") + if(dm[0].count(cc) == 0) + c = cc; + } + if(wait_counter > 20) + c = 'A'; + } else { + wait_counter = 0; + } if(c != 'A') g.command(c); return c; } @@ -621,13 +636,14 @@ { if(c != 'A') g.command(c); } - char think(in Game g) - { + int wait_counter = 0; + char think(in Game g, string death) + { auto Q = new Queue!(Tuple!(Pos,Pos)); Q.push(tuple(g.map.robot.clone(), g.map.robot.clone()), 0); Pos[][] V = new Pos[][](g.map.H+2, g.map.W+2); while(!Q.empty) { auto tup = Q.pop(); @@ -654,22 +670,24 @@ } int[4] dy=[-1,+1,0,0]; int[4] dx=[0,0,-1,+1]; char[] ds=['D','U','L','R']; - for(int i=0; i<4; ++i) - { + for(int i=0; i<4; ++i) { + if(g.map.robot==p && death.count(ds[i])) + continue; int y=p.y+dy[i], x=p.x+dx[i]; if((g.map[y,x]==' '||g.map[y,x]=='\\'||g.map[y,x]=='.'||g.map[y,x]=='O')&&!V[y][x]) { Q.push(tuple(new Pos(y,x),p), dist+1); } } } - return 'A'; + + return 'W'; } } //alias 侵掠如火!(疾如風) MainSolver; -alias 侵掠如火!(徐如林) MainSolver; -//alias 疾如風 MainSolver; +//alias 侵掠如火!(徐如林) MainSolver; +alias 疾如風 MainSolver; //alias 徐如林 MainSolver; //alias 不動如山 MainSolver;