Differences From Artifact [89ef01bfcc63d3cd]:
- File
src/game.d
- 2012-07-15 02:05:53 - part of checkin [41c73506fb] on branch trunk - Gets razor. (user: kinaba) [annotate]
To Artifact [09842c914b3d99f0]:
- File
src/game.d
- 2012-07-15 02:11:16 - part of checkin [3a08e528e7] on branch trunk - Using razor. (user: kinaba) [annotate]
236 236 if(this[y,x] == 'L' || this[y,x] == 'O')
237 237 return false;
238 238 return true;
239 239 }
240 240
241 241 Tuple!(int,bool) command(char c, int turn)
242 242 {
243 + assert( this[robot] == 'R' );
243 244 if(c=='R') return move( 0, +1, turn);
244 245 if(c=='L') return move( 0, -1, turn);
245 246 if(c=='U') return move(+1, 0, turn);
246 247 if(c=='D') return move(-1, 0, turn);
247 248 if(c=='W') return move( 0, 0, turn);
249 + if(c=='S') return use_razor(turn);
248 250 assert(false);
249 251 }
252 +
253 + Tuple!(int, bool) use_razor(int turn)
254 + {
255 + if(razor) {
256 + razor--;
257 + for(int dy=-1; dy<=+1; ++dy)
258 + for(int dx=-1; dx<=+1; ++dx)
259 + if(this[robot.y+dy,robot.x+dx] == 'W')
260 + this[robot.y+dy,robot.x+dx] = ' ';
261 + }
262 +
263 + bool dead = update(turn);
264 + return tuple(0,dead);
265 + }
250 266
251 267 Tuple!(int, bool) move(int dy, int dx, int turn)
252 268 {
253 269 int y = robot.y;
254 270 int x = robot.x;
255 - assert( this[robot] == 'R' );
256 271 int lambda = 0;
257 - bool dead = false;
258 272 if( '\\' == this[y+dy,x+dx] )
259 273 lambda++;
260 274 if( '!' == this[y+dy,x+dx] )
261 275 razor++;
262 276 if( " \\!.O".count(this[y+dy,x+dx])==1 ) {
263 277 this[y,x]=' ';
264 278 this[y+dy,x+dx]='R';
................................................................................
272 286 this[y,x]=' ';
273 287 Pos tp = tr_target[this[y+dy,x+dx]];
274 288 foreach(p; tr_source[this[tp]])
275 289 this[p] = ' ';
276 290 this[tp] = 'R';
277 291 robot = tp;
278 292 }
279 - if( update(turn) )
280 - dead = true;
293 + bool dead = update(turn);
281 294 return tuple(lambda,dead);
282 295 }
283 296
284 297 bool update(int turn)
285 298 {
286 299 bool dead = false;
287 300