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 if(this[y,x] == 'L' || this[y,x] == 'O') 236 if(this[y,x] == 'L' || this[y,x] == 'O')
237 return false; 237 return false;
238 return true; 238 return true;
239 } 239 }
240 240
241 Tuple!(int,bool) command(char c, int turn) 241 Tuple!(int,bool) command(char c, int turn)
242 { 242 {
> 243 assert( this[robot] == 'R' );
243 if(c=='R') return move( 0, +1, turn); 244 if(c=='R') return move( 0, +1, turn);
244 if(c=='L') return move( 0, -1, turn); 245 if(c=='L') return move( 0, -1, turn);
245 if(c=='U') return move(+1, 0, turn); 246 if(c=='U') return move(+1, 0, turn);
246 if(c=='D') return move(-1, 0, turn); 247 if(c=='D') return move(-1, 0, turn);
247 if(c=='W') return move( 0, 0, turn); 248 if(c=='W') return move( 0, 0, turn);
> 249 if(c=='S') return use_razor(turn);
248 assert(false); 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 Tuple!(int, bool) move(int dy, int dx, int turn) 267 Tuple!(int, bool) move(int dy, int dx, int turn)
252 { 268 {
253 int y = robot.y; 269 int y = robot.y;
254 int x = robot.x; 270 int x = robot.x;
255 assert( this[robot] == 'R' ); <
256 int lambda = 0; 271 int lambda = 0;
257 bool dead = false; <
258 if( '\\' == this[y+dy,x+dx] ) 272 if( '\\' == this[y+dy,x+dx] )
259 lambda++; 273 lambda++;
260 if( '!' == this[y+dy,x+dx] ) 274 if( '!' == this[y+dy,x+dx] )
261 razor++; 275 razor++;
262 if( " \\!.O".count(this[y+dy,x+dx])==1 ) { 276 if( " \\!.O".count(this[y+dy,x+dx])==1 ) {
263 this[y,x]=' '; 277 this[y,x]=' ';
264 this[y+dy,x+dx]='R'; 278 this[y+dy,x+dx]='R';
................................................................................................................................................................................
272 this[y,x]=' '; 286 this[y,x]=' ';
273 Pos tp = tr_target[this[y+dy,x+dx]]; 287 Pos tp = tr_target[this[y+dy,x+dx]];
274 foreach(p; tr_source[this[tp]]) 288 foreach(p; tr_source[this[tp]])
275 this[p] = ' '; 289 this[p] = ' ';
276 this[tp] = 'R'; 290 this[tp] = 'R';
277 robot = tp; 291 robot = tp;
278 } 292 }
279 if( update(turn) ) | 293 bool dead = update(turn);
280 dead = true; <
281 return tuple(lambda,dead); 294 return tuple(lambda,dead);
282 } 295 }
283 296
284 bool update(int turn) 297 bool update(int turn)
285 { 298 {
286 bool dead = false; 299 bool dead = false;
287 300