Exemple #1
0
 private bool Contains(PositionMower futurePosition)
 {
     return(futurePosition.X >= 0 &&
            futurePosition.X <= _width &&
            futurePosition.Y >= 0 &&
            futurePosition.Y <= _height);
 }
Exemple #2
0
        public PositionMower ApplyCommand(PositionMower position, Command command)
        {
            PositionMower positionMower;

            switch (command)
            {
            case Command.Left:
                positionMower = position.RotateToLeft();
                break;

            case Command.Right:
                positionMower = position.RotateToRight();
                break;

            case Command.Forward:
                positionMower = position.MoveForward(this);
                break;;

            default:
                throw new ArgumentOutOfRangeException(nameof(command), command, null);
            }

            Track(positionMower);
            return(positionMower);
        }
Exemple #3
0
        public PositionMower MoveForward(Lawn lawn)
        {
            PositionMower futurePositionMower = PredictPosition();

            return(lawn.CanMoveInThisPosition(futurePositionMower)
                ? futurePositionMower
                : this);
        }
Exemple #4
0
        public static Dictionary <PositionMower, Command[]> ParseCommandOnMower(string[] splittedInput)
        {
            Dictionary <PositionMower, Command[]> dic = new Dictionary <PositionMower, Command[]>();

            for (int indexMower = 0; indexMower < splittedInput.Length / 2; indexMower++)
            {
                PositionMower positionMower = ParsePosition(splittedInput[2 * indexMower + 1], indexMower);
                Command[]     commands      = ParseCommand(splittedInput[2 * indexMower + 2]);
                dic.Add(positionMower, commands);
            }

            return(dic);
        }
Exemple #5
0
 public bool IsSameCoordinate(PositionMower positionMower)
 {
     return(positionMower.X == X && positionMower.Y == Y);
 }
Exemple #6
0
 private bool AnotherMowerInThisPosition(PositionMower positionMower)
 {
     return(_positionMowers.Any(p =>
                                p.IdMower != positionMower.IdMower &&
                                p.IsSameCoordinate(positionMower)));
 }
Exemple #7
0
 public bool CanMoveInThisPosition(PositionMower futurePositionMower)
 {
     return(Contains(futurePositionMower) &&
            !AnotherMowerInThisPosition(futurePositionMower));
 }
Exemple #8
0
 private void Track(PositionMower positionMower)
 {
     _positionMowers[positionMower.IdMower] = positionMower;
 }