Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 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;
     }
 }
Ejemplo n.º 3
0
        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);
            }
        }