private bool Contains(PositionMower futurePosition) { return(futurePosition.X >= 0 && futurePosition.X <= _width && futurePosition.Y >= 0 && futurePosition.Y <= _height); }
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); }
public PositionMower MoveForward(Lawn lawn) { PositionMower futurePositionMower = PredictPosition(); return(lawn.CanMoveInThisPosition(futurePositionMower) ? futurePositionMower : this); }
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); }
public bool IsSameCoordinate(PositionMower positionMower) { return(positionMower.X == X && positionMower.Y == Y); }
private bool AnotherMowerInThisPosition(PositionMower positionMower) { return(_positionMowers.Any(p => p.IdMower != positionMower.IdMower && p.IsSameCoordinate(positionMower))); }
public bool CanMoveInThisPosition(PositionMower futurePositionMower) { return(Contains(futurePositionMower) && !AnotherMowerInThisPosition(futurePositionMower)); }
private void Track(PositionMower positionMower) { _positionMowers[positionMower.IdMower] = positionMower; }