Beispiel #1
0
        public MoveRoverResult TryMoveRover(List <Movement> movements, Rover rover)
        {
            Coordinate startingPoint     = _context.GetCoordinateByRover(rover);
            Direction  startingDirection = rover.CurrentDirection;

            foreach (Movement movement in movements)
            {
                if (movement == Movement.Left)
                {
                    rover.Left();
                }
                else if (movement == Movement.Right)
                {
                    rover.Right();
                }
                else
                {
                    LegalityOfMove result = _context.TryMove(rover);
                    if (result.IsLegal())
                    {
                        continue;
                    }
                    ResetRoverOnBoard(rover, startingDirection, startingPoint);
                    return(new MoveRoverResult(_context.GetCoordinateByRover(rover), rover, result));
                }
            }
            return(new MoveRoverResult(_context.GetCoordinateByRover(rover), rover, new LegalityOfMove(false, false)));
        }
Beispiel #2
0
        public LegalityOfMove TryMove(Rover rover)
        {
            var            next = GetCoordinateByRover(rover).GetNext(rover.CurrentDirection);
            LegalityOfMove ans  = LegalCoordinate(next);

            if (ans.IsLegal())
            {
                Remove(rover);
                AddRover(rover, next);
            }
            return(ans);
        }
Beispiel #3
0
        public AddRoverResult AddRover(NewRoverInput roverInput)
        {
            LegalityOfMove result = _context.LegalCoordinate(roverInput.Coordinate);

            if (!result.IsLegal())
            {
                return(new AddRoverResult(false, null, result));
            }
            var rover = new Rover("Rover " + (_context.GetTotalRovers() + 1), roverInput.Direction);

            _context.AddRover(rover, roverInput.Coordinate);
            return(new AddRoverResult(true, rover, result));
        }