Index: src/solver.d ================================================================== --- src/solver.d +++ src/solver.d @@ -26,29 +26,41 @@ this.g = g.clone(); } char single_step() { - char c = act(g); + char c = act(g, death_move(g)); g.command(c); return c; } - char act(const(Game) g) + string death_move(const(Game) g) + { + string death; + foreach(char c; "UDLRW") { + Game gg = g.clone(); + gg.command(c); + if( !gg.cleared && gg.dead ) + death ~= c; + } + return death; + } + + char act(const(Game) g, string death) { const Pos ro = g.map.robot; const Pos[] la = g.map.lambdas(); const Pos li = g.map.lift; char c = 'W'; if( la.empty ) { - auto r = search(g, ro, li); + auto r = search(g, ro, li, death); c = r[0]; } else { Tuple!(char,int)[] cand; foreach(lam; la) - cand ~= search(g, ro, lam); + cand ~= search(g, ro, lam, death); sort!((Tuple!(char,int) c1, Tuple!(char,int) c2){ if(c1[1] != c2[1]) return c1[1] < c2[1]; return c1[0] < c2[0]; })(cand); @@ -62,11 +74,11 @@ else g_wc = 0; return c; } - Tuple!(char,int) search(in Game g, in Pos s, in Pos o) + Tuple!(char,int) search(in Game g, in Pos s, in Pos o, string death) { const(Pos)[] q = [o]; bool[][] v = new bool[][](g.map.H+2, g.map.W+2); for(int step=1; q.length; ++step) { Pos[] q2; @@ -76,14 +88,13 @@ for(int i=0; i<4; ++i) { int y = p.y+dy[i]; int x = p.x+dx[i]; if(v[y][x]) continue; if(y==s.y && x==s.x) { - if(i==0) return tuple('U',step); - if(i==1) return tuple('D',step); - if(i==2) return tuple('R',step); - if(i==3) return tuple('L',step); + char c = "UDRL"[i]; + if( death.count(c) == 0 ) + return tuple(c,step); } else if(g.map[y,x]==' '||g.map[y,x]=='\\') { q2 ~= new Pos(y,x); v[y][x]=true; } else if(g.map[y,x]=='.' && g.map[y-1,x]!='*') { q2 ~= new Pos(y,x); @@ -103,14 +114,13 @@ for(int i=0; i<4; ++i) { int y = p.y+dy[i]; int x = p.x+dx[i]; if(v[y][x]) continue; if(y==s.y && x==s.x) { - if(i==0) return tuple('U',step); - if(i==1) return tuple('D',step); - if(i==2) return tuple('R',step); - if(i==3) return tuple('L',step); + char c = "UDRL"[i]; + if( death.count(c) == 0 ) + return tuple(c,step); } else if(g.map[y,x]==' '||g.map[y,x]=='\\') { q2 ~= new Pos(y,x); v[y][x]=true; } else if(g.map[y,x]=='.'/* && g[y-1,x]!='*'*/) { q2 ~= new Pos(y,x);