Diff
Not logged in

Differences From Artifact [8291f785bb7f35e6]:

To Artifact [2d52631f9ee4aac8]:


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