Index: src/game.d ================================================================== --- src/game.d +++ src/game.d @@ -238,25 +238,39 @@ return true; } Tuple!(int,bool) command(char c, int turn) { + assert( this[robot] == 'R' ); if(c=='R') return move( 0, +1, turn); if(c=='L') return move( 0, -1, turn); if(c=='U') return move(+1, 0, turn); if(c=='D') return move(-1, 0, turn); if(c=='W') return move( 0, 0, turn); + if(c=='S') return use_razor(turn); assert(false); } + + Tuple!(int, bool) use_razor(int turn) + { + if(razor) { + razor--; + for(int dy=-1; dy<=+1; ++dy) + for(int dx=-1; dx<=+1; ++dx) + if(this[robot.y+dy,robot.x+dx] == 'W') + this[robot.y+dy,robot.x+dx] = ' '; + } + + bool dead = update(turn); + return tuple(0,dead); + } Tuple!(int, bool) move(int dy, int dx, int turn) { int y = robot.y; int x = robot.x; - assert( this[robot] == 'R' ); int lambda = 0; - bool dead = false; if( '\\' == this[y+dy,x+dx] ) lambda++; if( '!' == this[y+dy,x+dx] ) razor++; if( " \\!.O".count(this[y+dy,x+dx])==1 ) { @@ -274,12 +288,11 @@ foreach(p; tr_source[this[tp]]) this[p] = ' '; this[tp] = 'R'; robot = tp; } - if( update(turn) ) - dead = true; + bool dead = update(turn); return tuple(lambda,dead); } bool update(int turn) { Index: src/gui.d ================================================================== --- src/gui.d +++ src/gui.d @@ -141,13 +141,14 @@ case Keys.DOWN: fn('D'); break; case Keys.UP: fn('U'); break; case Keys.LEFT: fn('L'); break; case Keys.RIGHT: fn('R'); break; case Keys.W: fn('W'); break; + case Keys.S: fn('S'); break; case Keys.A: fn('A'); break; case Keys.G: fn(solver.single_step()); break; default: break; } } Solver solver; }