Diff
Not logged in

Differences From Artifact [8291f785bb7f35e6]:

To Artifact [2d52631f9ee4aac8]:


185 for(int x=0; x<W; ++x) 185 for(int x=0; x<W; ++x) 186 if(data[y][x]=='R') 186 if(data[y][x]=='R') 187 sy=y, sx=x; 187 sy=y, sx=x; 188 else if(data[y][x]=='\\') 188 else if(data[y][x]=='\\') 189 ly~=y, lx~=x; 189 ly~=y, lx~=x; 190 else if(data[y][x]=='O') 190 else if(data[y][x]=='O') 191 oy=y, ox=x; 191 oy=y, ox=x; 192 if(ly.length==0) | 192 if(ly.length==0) { 193 return goal(sy,sx,oy,ox); | 193 auto r = search(sy,sx,oy,ox); > 194 switch(r[0]) { > 195 case 'D': return command_D(); > 196 case 'U': return command_U(); > 197 case 'L': return command_L(); > 198 case 'R': return command_R(); > 199 case 'A': return abort(); > 200 default: return wait(); > 201 } > 202 } 194 return wait(); 203 return wait(); 195 } 204 } 196 int goal(int sy, int sx, int oy, int ox) | 205 Tuple!(char,int) search(int sy, int sx, int oy, int ox) 197 { 206 { 198 alias Tuple!(int,"y",int,"x") Pt; 207 alias Tuple!(int,"y",int,"x") Pt; 199 Pt[] q = [Pt(oy,ox)]; 208 Pt[] q = [Pt(oy,ox)]; 200 while(q.length) { | 209 for(int step=1; q.length; ++step) { 201 Pt[] q2; 210 Pt[] q2; 202 foreach(p; q) { 211 foreach(p; q) { 203 212 204 int[] dy=[-1,+1,0,0]; 213 int[] dy=[-1,+1,0,0]; 205 int[] dx=[0,0,-1,+1]; 214 int[] dx=[0,0,-1,+1]; 206 for(int i=0; i<4; ++i) { 215 for(int i=0; i<4; ++i) { 207 int y = p.y+dy[i]; 216 int y = p.y+dy[i]; 208 int x = p.x+dx[i]; 217 int x = p.x+dx[i]; 209 if(y==sy && x==sx) { 218 if(y==sy && x==sx) { 210 if(i==0) return command_D(); | 219 if(i==0) return tuple('D',step); 211 if(i==1) return command_U(); | 220 if(i==1) return tuple('U',step); 212 if(i==2) return command_R(); | 221 if(i==2) return tuple('R',step); 213 if(i==3) return command_L(); | 222 if(i==3) return tuple('L',step); 214 } else if(data[y][x]==' ') { | 223 } else if(data[y][x]==' '||data[y][x]==' 215 q2 ~= Pt(y,x); 224 q2 ~= Pt(y,x); 216 } else if(data[y][x]=='.' && data[y-1][x 225 } else if(data[y][x]=='.' && data[y-1][x 217 q2 ~= Pt(y,x); 226 q2 ~= Pt(y,x); 218 } 227 } 219 } 228 } 220 } 229 } 221 q = q2; 230 q = q2; 222 } 231 } 223 q = [Pt(oy,ox)]; 232 q = [Pt(oy,ox)]; 224 while(q.length) { | 233 for(int step=1<<10; q.length; ++step) { 225 Pt[] q2; 234 Pt[] q2; 226 foreach(p; q) { 235 foreach(p; q) { 227 236 228 int[] dy=[-1,+1,0,0]; 237 int[] dy=[-1,+1,0,0]; 229 int[] dx=[0,0,-1,+1]; 238 int[] dx=[0,0,-1,+1]; 230 for(int i=0; i<4; ++i) { 239 for(int i=0; i<4; ++i) { 231 int y = p.y+dy[i]; 240 int y = p.y+dy[i]; 232 int x = p.x+dx[i]; 241 int x = p.x+dx[i]; 233 if(y==sy && x==sx) { 242 if(y==sy && x==sx) { 234 if(i==0) return command_D(); | 243 if(i==0) return tuple('D',step); 235 if(i==1) return command_U(); | 244 if(i==1) return tuple('U',step); 236 if(i==2) return command_R(); | 245 if(i==2) return tuple('R',step); 237 if(i==3) return command_L(); | 246 if(i==3) return tuple('L',step); 238 } else if(data[y][x]==' ') { | 247 } else if(data[y][x]==' '||data[y][x]==' 239 q2 ~= Pt(y,x); 248 q2 ~= Pt(y,x); 240 } else if(data[y][x]=='.'/* && data[y-1] 249 } else if(data[y][x]=='.'/* && data[y-1] 241 q2 ~= Pt(y,x); 250 q2 ~= Pt(y,x); 242 } 251 } 243 } 252 } 244 } 253 } 245 q = q2; 254 q = q2; 246 } 255 } 247 return abort(); | 256 return tuple('A',int.max); 248 } 257 } 249 } 258 } 250 259 251 class MyForm : Form 260 class MyForm : Form 252 { 261 { 253 Map m; 262 Map m; 254 int score; 263 int score;