Differences From Artifact [4262c5e337ee629c]:
- File
test.d
- 2012-07-14 02:13:47 - part of checkin [05e91f8e53] on branch trunk - add infra for clever command. (user: kinaba) [annotate]
To Artifact [6402a11e444d2d1e]:
- File
test.d
- 2012-07-14 02:16:04 - part of checkin [d9fd2b855a] on branch trunk - Clever command now outputs the command sequence. (user: kinaba) [annotate]
62 if(i) result ~= '\n'; 62 if(i) result ~= '\n';
63 result ~= s.idup; 63 result ~= s.idup;
64 } 64 }
65 return result; 65 return result;
66 } 66 }
67 } 67 }
68 68
69 int command_R() { return move(0, +1); } | 69 int command_R() { if(dead)return 0; write("R"); return move(0, +1); }
70 int command_L() { return move(0, -1); } | 70 int command_L() { if(dead)return 0; write("L"); return move(0, -1); }
71 int command_U() { return move(-1, 0); } | 71 int command_U() { if(dead)return 0; write("U"); return move(-1, 0); }
72 int command_D() { return move(+1, 0); } | 72 int command_D() { if(dead)return 0; write("D"); return move(+1, 0); }
73 int wait() { if(dead)return 0; update(); return -1; } | 73 int wait() { if(dead)return 0; update(); write("W"); return -1; }
74 int abort() { if(dead)return 0; cleared=true; return gained*25; } | 74 int abort() { if(dead)return 0; cleared=true; write("A"); return gained*
75 75
76 int move(int dy, int dx) { 76 int move(int dy, int dx) {
77 foreach(y,s; data) 77 foreach(y,s; data)
78 foreach(x,c; s) 78 foreach(x,c; s)
79 if(c == 'R') 79 if(c == 'R')
80 return move(dy, dx, y, x); 80 return move(dy, dx, y, x);
81 assert(false); 81 assert(false);
................................................................................................................................................................................
190 oy=y, ox=x; 190 oy=y, ox=x;
191 if(ly.length==0) 191 if(ly.length==0)
192 return goal(sy,sx,oy,ox); 192 return goal(sy,sx,oy,ox);
193 return wait(); 193 return wait();
194 } 194 }
195 int goal(int sy, int sx, int oy, int ox) 195 int goal(int sy, int sx, int oy, int ox)
196 { 196 {
> 197 return wait();
197 } 198 }
198 } 199 }
199 200
200 class MyForm : Form 201 class MyForm : Form
201 { 202 {
202 Map m; 203 Map m;
203 int score; 204 int score;
................................................................................................................................................................................
249 } 250 }
250 void myKey(Control c, KeyEventArgs ev) 251 void myKey(Control c, KeyEventArgs ev)
251 { 252 {
252 switch(ev.keyCode) 253 switch(ev.keyCode)
253 { 254 {
254 case Keys.DOWN: 255 case Keys.DOWN:
255 score += m.command_D(); 256 score += m.command_D();
256 write("D"); <
257 stdout.flush(); 257 stdout.flush();
258 break; 258 break;
259 case Keys.UP: 259 case Keys.UP:
260 score += m.command_U(); 260 score += m.command_U();
261 write("U"); <
262 stdout.flush(); 261 stdout.flush();
263 break; 262 break;
264 case Keys.LEFT: 263 case Keys.LEFT:
265 score += m.command_L(); 264 score += m.command_L();
266 write("L"); <
267 stdout.flush(); 265 stdout.flush();
268 break; 266 break;
269 case Keys.RIGHT: 267 case Keys.RIGHT:
270 score += m.command_R(); 268 score += m.command_R();
271 write("R"); <
272 stdout.flush(); 269 stdout.flush();
273 break; 270 break;
274 case Keys.W: 271 case Keys.W:
275 score += m.wait(); 272 score += m.wait();
276 write("W"); <
277 stdout.flush(); 273 stdout.flush();
278 break; 274 break;
279 case Keys.A: 275 case Keys.A:
280 score += m.abort(); 276 score += m.abort();
281 write("A"); <
282 stdout.flush(); 277 stdout.flush();
283 break; 278 break;
284 case Keys.G: 279 case Keys.G:
285 score += m.clever(); 280 score += m.clever();
286 write("_"); <
287 stdout.flush(); 281 stdout.flush();
288 break; 282 break;
289 default: 283 default:
290 break; 284 break;
291 } 285 }
292 if(m.cleared) { 286 if(m.cleared) {
293 writeln(); 287 writeln();