Check-in [3a08e528e7]
Not logged in
Overview
SHA1 Hash:3a08e528e71ee872f10fae14328efc3e2766480c
Date: 2012-07-15 11:11:16
User: kinaba
Comment:Using razor.
Timelines: family | ancestors | descendants | both | trunk
Diffs: redesign
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Modified src/game.d from [89ef01bfcc63d3cd] to [09842c914b3d99f0].

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

Modified src/gui.d from [3be06eef4f2a58fa] to [b071b446f6e834b9].

139 switch(ev.keyCode) 139 switch(ev.keyCode) 140 { 140 { 141 case Keys.DOWN: fn('D'); break; 141 case Keys.DOWN: fn('D'); break; 142 case Keys.UP: fn('U'); break; 142 case Keys.UP: fn('U'); break; 143 case Keys.LEFT: fn('L'); break; 143 case Keys.LEFT: fn('L'); break; 144 case Keys.RIGHT: fn('R'); break; 144 case Keys.RIGHT: fn('R'); break; 145 case Keys.W: fn('W'); break; 145 case Keys.W: fn('W'); break; > 146 case Keys.S: fn('S'); break; 146 case Keys.A: fn('A'); break; 147 case Keys.A: fn('A'); break; 147 case Keys.G: fn(solver.single_step()); break; 148 case Keys.G: fn(solver.single_step()); break; 148 default: break; 149 default: break; 149 } 150 } 150 } 151 } 151 152 152 Solver solver; 153 Solver solver; 153 } 154 }