Check-in [5fc8a9c49b]
Not logged in
Overview
SHA1 Hash:5fc8a9c49b42006a06c3e9acdfc371a23c68ec51
Date: 2012-07-14 22:21:56
User: kinaba
Comment:rock pusher.
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 [e22cb888fb6353ea] to [6098061a6d0ff01b].

74 else 74 else 75 g_wc = 0; 75 g_wc = 0; 76 return c; 76 return c; 77 } 77 } 78 78 79 Tuple!(char,int) search(in Game g, in Pos s, in Pos o, string death) 79 Tuple!(char,int) search(in Game g, in Pos s, in Pos o, string death) 80 { 80 { > 81 // avoid directly below '*' 81 const(Pos)[] q = [o]; 82 const(Pos)[] q = [o]; 82 bool[][] v = new bool[][](g.map.H+2, g.map.W+2); 83 bool[][] v = new bool[][](g.map.H+2, g.map.W+2); > 84 v[o.y][o.x]=true; 83 for(int step=1; q.length; ++step) { 85 for(int step=1; q.length; ++step) { 84 Pos[] q2; 86 Pos[] q2; 85 foreach(p; q) { 87 foreach(p; q) { 86 int[] dy=[-1,+1,0,0]; 88 int[] dy=[-1,+1,0,0]; 87 int[] dx=[0,0,-1,+1]; 89 int[] dx=[0,0,-1,+1]; 88 for(int i=0; i<4; ++i) { 90 for(int i=0; i<4; ++i) { 89 int y = p.y+dy[i]; 91 int y = p.y+dy[i]; ................................................................................................................................................................................ 100 q2 ~= new Pos(y,x); 102 q2 ~= new Pos(y,x); 101 v[y][x]=true; 103 v[y][x]=true; 102 } 104 } 103 } 105 } 104 } 106 } 105 q = q2; 107 q = q2; 106 } 108 } > 109 > 110 // any empty space is my ground 107 q = [o]; 111 q = [o]; 108 v = new bool[][](g.map.H+2, g.map.W+2); 112 v = new bool[][](g.map.H+2, g.map.W+2); > 113 v[o.y][o.x]=true; 109 for(int step=1000; q.length; ++step) { 114 for(int step=1000; q.length; ++step) { 110 Pos[] q2; 115 Pos[] q2; 111 foreach(p; q) { 116 foreach(p; q) { 112 int[] dy=[-1,+1,0,0]; 117 int[] dy=[-1,+1,0,0]; 113 int[] dx=[0,0,-1,+1]; 118 int[] dx=[0,0,-1,+1]; 114 for(int i=0; i<4; ++i) { 119 for(int i=0; i<4; ++i) { 115 int y = p.y+dy[i]; 120 int y = p.y+dy[i]; ................................................................................................................................................................................ 123 q2 ~= new Pos(y,x); 128 q2 ~= new Pos(y,x); 124 v[y][x]=true; 129 v[y][x]=true; 125 } else if(g.map[y,x]=='.'/* && g[y-1,x]! 130 } else if(g.map[y,x]=='.'/* && g[y-1,x]! 126 q2 ~= new Pos(y,x); 131 q2 ~= new Pos(y,x); 127 v[y][x]=true; 132 v[y][x]=true; 128 } 133 } 129 } 134 } > 135 } > 136 q = q2; > 137 } > 138 > 139 // push rocks! > 140 q = [o]; > 141 v = new bool[][](g.map.H+2, g.map.W+2); > 142 v[o.y][o.x]=true; > 143 for(int step=2000; q.length; ++step) { > 144 Pos[] q2; > 145 foreach(p; q) { > 146 int[] dy=[-1,+1,0,0]; > 147 int[] dx=[0,0,-1,+1]; > 148 for(int i=0; i<4; ++i) { > 149 int y = p.y+dy[i]; > 150 int x = p.x+dx[i]; > 151 if(v[y][x]) continue; > 152 if(y==s.y && x==s.x) { > 153 char c = "UDRL"[i]; > 154 if( death.count(c) == 0 ) > 155 return tuple(c,step); > 156 } else if(g.map[y,x]==' '||g.map[y,x]==' > 157 q2 ~= new Pos(y,x); > 158 v[y][x]=true; > 159 } else if(g.map[y,x]=='.'/* && g[y-1,x]! > 160 q2 ~= new Pos(y,x); > 161 v[y][x]=true; > 162 } else if(dy[i]==0 && g.map[y,x]=='*' && > 163 q2 ~= new Pos(y,x); > 164 v[y][x]=true; > 165 } > 166 } 130 } 167 } 131 q = q2; 168 q = q2; 132 } 169 } 133 return tuple('W', int.max); 170 return tuple('W', int.max); 134 } 171 } 135 } 172 }