public RobotCommand ExecuteTurn(RobotCommand command) { IsChanged = false; Moves.Enqueue(command); NeighborCache.Clear(); switch (command) { case RobotCommand.Up: MoveRobotTo(RobotCommand.Up, RobotPosition.Up()); break; case RobotCommand.Down: MoveRobotTo(RobotCommand.Down, RobotPosition.Down()); break; case RobotCommand.Left: MoveRobotTo(RobotCommand.Left, RobotPosition.Left()); break; case RobotCommand.Right: MoveRobotTo(RobotCommand.Right, RobotPosition.Right()); break; case RobotCommand.Abort: State = MapState.Aborted; Score = AbortScore; break; case RobotCommand.Shave: for (int dy = -1; dy < 2; dy++) { for (int dx = -1; dx < 2; dx++) { if (Cell.At(RobotPosition.X + dx, RobotPosition.Y + dy).IsBeard()) { Cell.Set(RobotPosition.X + dx, RobotPosition.Y + dy, CellType.Empty); IsChanged = true; } } } break; } if (State == MapState.Valid) { Score -= 1; Simulate(); } return(command); }
public void Move(char currentHeading, RobotPosition currentRobotPosition) { switch (currentHeading) { case 'N': currentRobotPosition.Up(); break; case 'E': currentRobotPosition.Right(); break; case 'W': currentRobotPosition.Left(); break; case 'S': currentRobotPosition.Down(); break; } }
public bool IsValidCommand(RobotCommand command) { switch (command) { case RobotCommand.Up: return(Cell.IsValidMove(RobotPosition, RobotPosition.Up())); case RobotCommand.Down: return(Cell.IsValidMove(RobotPosition, RobotPosition.Down())); case RobotCommand.Left: return(Cell.IsValidMove(RobotPosition, RobotPosition.Left())); case RobotCommand.Right: return(Cell.IsValidMove(RobotPosition, RobotPosition.Right())); default: return(true); } }