Overview
SHA1 Hash: | 4bdb07bffb25e219a086769a1044010fe0039618 |
---|---|
Date: | 2012-07-14 11:29:29 |
User: | kinaba |
Comment: | auto go-home. |
Timelines: | family | ancestors | descendants | both | trunk |
Diffs: | redesign |
Downloads: | Tarball | ZIP archive |
Other Links: | files | file ages | manifest |
Tags And Properties
- branch=trunk inherited from [16f0b5784f]
- sym-trunk inherited from [16f0b5784f]
Changes
Modified test.d from [6402a11e444d2d1e] to [8291f785bb7f35e6].
1 1 import std.algorithm; 2 2 import std.array; 3 3 import std.conv; 4 4 import std.stdio; 5 5 import std.string; 6 +import std.typecons; 6 7 import dfl.all; 7 8 8 9 class Map 9 10 { 10 11 private char[][] data; 11 12 bool dead = false; 12 13 bool cleared = false; ................................................................................ 190 191 oy=y, ox=x; 191 192 if(ly.length==0) 192 193 return goal(sy,sx,oy,ox); 193 194 return wait(); 194 195 } 195 196 int goal(int sy, int sx, int oy, int ox) 196 197 { 197 - return wait(); 198 + alias Tuple!(int,"y",int,"x") Pt; 199 + Pt[] q = [Pt(oy,ox)]; 200 + while(q.length) { 201 + Pt[] q2; 202 + foreach(p; q) { 203 + 204 + int[] dy=[-1,+1,0,0]; 205 + int[] dx=[0,0,-1,+1]; 206 + for(int i=0; i<4; ++i) { 207 + int y = p.y+dy[i]; 208 + int x = p.x+dx[i]; 209 + 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]==' ') { 215 + q2 ~= Pt(y,x); 216 + } else if(data[y][x]=='.' && data[y-1][x]!='*') { 217 + q2 ~= Pt(y,x); 218 + } 219 + } 220 + } 221 + q = q2; 222 + } 223 + q = [Pt(oy,ox)]; 224 + while(q.length) { 225 + Pt[] q2; 226 + foreach(p; q) { 227 + 228 + int[] dy=[-1,+1,0,0]; 229 + int[] dx=[0,0,-1,+1]; 230 + for(int i=0; i<4; ++i) { 231 + int y = p.y+dy[i]; 232 + int x = p.x+dx[i]; 233 + 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]==' ') { 239 + q2 ~= Pt(y,x); 240 + } else if(data[y][x]=='.'/* && data[y-1][x]!='*'*/) { 241 + q2 ~= Pt(y,x); 242 + } 243 + } 244 + } 245 + q = q2; 246 + } 247 + return abort(); 198 248 } 199 249 } 200 250 201 251 class MyForm : Form 202 252 { 203 253 Map m; 204 254 int score;