@@ -52,12 +52,11 @@ Tuple!(char,int)[] cand; char c = 'W'; if( la.empty ) { - cand = search(g, ro, li, death); + cand = search(g, ro, [li], death); } else { - foreach(lam; la) - cand ~= search(g, ro, lam, death); + cand ~= search(g, ro, la, death); } cand ~= tuple('W',int.max); sort!((Tuple!(char,int) c1, Tuple!(char,int) c2){ if(c1[1] != c2[1]) @@ -98,9 +97,9 @@ return c; } - Tuple!(char,int)[] search(in Game g, in Pos s, in Pos o, string death) + Tuple!(char,int)[] search(in Game g, in Pos s, in Pos[] gs, string death) { bool danger(int y, int x) { if(g.map[y+1,x] == '*') @@ -117,45 +116,47 @@ } // avoid directly below '*' Tuple!(char,int)[] tryA() { - const(Pos)[] q = [o]; + const(Pos)[] q; + foreach(p; gs) + if(!danger(p.y,p.x)) + q ~= p; bool[][] v = new bool[][](g.map.H+2, g.map.W+2); - if( !danger(o.y,o.x) ) { - v[o.y][o.x]=true; - for(int step=1; q.length; ++step) { - Pos[] q2; - foreach(p; q) { - int[] dy=[-1,+1,0,0]; - int[] dx=[0,0,-1,+1]; - 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) { - char c = "UDRL"[i]; - if( death.count(c) == 0 ) - return [tuple(c,step)]; - } else if(forbidden_cell[y][x]){ - } else if(g.map[y,x]==' '||g.map[y,x]=='\\'||g.map[y,x]=='.') { - if(danger(y,x)) - continue; - q2 ~= new Pos(y,x); - v[y][x]=true; - } + foreach(p; q) v[p.y][p.x]=true; + for(int step=1; q.length; ++step) { + Pos[] q2; + foreach(p; q) { + int[] dy=[-1,+1,0,0]; + int[] dx=[0,0,-1,+1]; + 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) { + char c = "UDRL"[i]; + if( death.count(c) == 0 ) + return [tuple(c,step)]; + } else if(forbidden_cell[y][x]){ + } else if(g.map[y,x]==' '||g.map[y,x]=='\\'||g.map[y,x]=='.') { + if(danger(y,x)) + continue; + q2 ~= new Pos(y,x); + v[y][x]=true; } } - q = q2; } + q = q2; } return []; } // any empty space is my ground Tuple!(char,int)[] tryB() { - const(Pos)[] q = [o]; + const(Pos)[] q; + foreach(p; gs) q ~= p; bool[][] v = new bool[][](g.map.H+2, g.map.W+2); - v[o.y][o.x]=true; + foreach(p; q) v[p.y][p.x]=true; for(int step=10; q.length; ++step) { Pos[] q2; foreach(p; q) { int[] dy=[-1,+1,0,0]; @@ -181,11 +182,12 @@ } // push rocks! Tuple!(char,int)[] tryC() { - const(Pos)[] q = [o]; + const(Pos)[] q; + foreach(p; gs) q ~= p; bool[][] v = new bool[][](g.map.H+2, g.map.W+2); - v[o.y][o.x]=true; + foreach(p; q) v[p.y][p.x]=true; for(int step=20; q.length; ++step) { Pos[] q2; foreach(p; q) { int[] dy=[-1,+1,0,0];