Check-in [b4aceba693]
Not logged in
Overview
SHA1 Hash:b4aceba6936dad82843a706f6d72794bcc98daf1
Date: 2012-07-14 22:02:03
User: kinaba
Comment:1 step death move detector rev.1
Timelines: family | ancestors | descendants | both | trunk
Diffs: redesign
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Modified src/solver.d from [0bb4050087a6fb3f] to [e22cb888fb6353ea].

24 24 this(const(Game) g) 25 25 { 26 26 this.g = g.clone(); 27 27 } 28 28 29 29 char single_step() 30 30 { 31 - char c = act(g); 31 + char c = act(g, death_move(g)); 32 32 g.command(c); 33 33 return c; 34 34 } 35 35 36 - char act(const(Game) g) 36 + string death_move(const(Game) g) 37 + { 38 + string death; 39 + foreach(char c; "UDLRW") { 40 + Game gg = g.clone(); 41 + gg.command(c); 42 + if( !gg.cleared && gg.dead ) 43 + death ~= c; 44 + } 45 + return death; 46 + } 47 + 48 + char act(const(Game) g, string death) 37 49 { 38 50 const Pos ro = g.map.robot; 39 51 const Pos[] la = g.map.lambdas(); 40 52 const Pos li = g.map.lift; 41 53 42 54 char c = 'W'; 43 55 if( la.empty ) { 44 - auto r = search(g, ro, li); 56 + auto r = search(g, ro, li, death); 45 57 c = r[0]; 46 58 } else { 47 59 Tuple!(char,int)[] cand; 48 60 foreach(lam; la) 49 - cand ~= search(g, ro, lam); 61 + cand ~= search(g, ro, lam, death); 50 62 sort!((Tuple!(char,int) c1, Tuple!(char,int) c2){ 51 63 if(c1[1] != c2[1]) 52 64 return c1[1] < c2[1]; 53 65 return c1[0] < c2[0]; 54 66 })(cand); 55 67 c = cand[0][0]; 56 68 } ................................................................................ 60 72 c = 'A'; 61 73 } 62 74 else 63 75 g_wc = 0; 64 76 return c; 65 77 } 66 78 67 - Tuple!(char,int) search(in Game g, in Pos s, in Pos o) 79 + Tuple!(char,int) search(in Game g, in Pos s, in Pos o, string death) 68 80 { 69 81 const(Pos)[] q = [o]; 70 82 bool[][] v = new bool[][](g.map.H+2, g.map.W+2); 71 83 for(int step=1; q.length; ++step) { 72 84 Pos[] q2; 73 85 foreach(p; q) { 74 86 int[] dy=[-1,+1,0,0]; 75 87 int[] dx=[0,0,-1,+1]; 76 88 for(int i=0; i<4; ++i) { 77 89 int y = p.y+dy[i]; 78 90 int x = p.x+dx[i]; 79 91 if(v[y][x]) continue; 80 92 if(y==s.y && x==s.x) { 81 - if(i==0) return tuple('U',step); 82 - if(i==1) return tuple('D',step); 83 - if(i==2) return tuple('R',step); 84 - if(i==3) return tuple('L',step); 93 + char c = "UDRL"[i]; 94 + if( death.count(c) == 0 ) 95 + return tuple(c,step); 85 96 } else if(g.map[y,x]==' '||g.map[y,x]=='\\') { 86 97 q2 ~= new Pos(y,x); 87 98 v[y][x]=true; 88 99 } else if(g.map[y,x]=='.' && g.map[y-1,x]!='*') { 89 100 q2 ~= new Pos(y,x); 90 101 v[y][x]=true; 91 102 } ................................................................................ 101 112 int[] dy=[-1,+1,0,0]; 102 113 int[] dx=[0,0,-1,+1]; 103 114 for(int i=0; i<4; ++i) { 104 115 int y = p.y+dy[i]; 105 116 int x = p.x+dx[i]; 106 117 if(v[y][x]) continue; 107 118 if(y==s.y && x==s.x) { 108 - if(i==0) return tuple('U',step); 109 - if(i==1) return tuple('D',step); 110 - if(i==2) return tuple('R',step); 111 - if(i==3) return tuple('L',step); 119 + char c = "UDRL"[i]; 120 + if( death.count(c) == 0 ) 121 + return tuple(c,step); 112 122 } else if(g.map[y,x]==' '||g.map[y,x]=='\\') { 113 123 q2 ~= new Pos(y,x); 114 124 v[y][x]=true; 115 125 } else if(g.map[y,x]=='.'/* && g[y-1,x]!='*'*/) { 116 126 q2 ~= new Pos(y,x); 117 127 v[y][x]=true; 118 128 }