public PositionMower MoveForward(Lawn lawn) { PositionMower futurePositionMower = PredictPosition(); return(lawn.CanMoveInThisPosition(futurePositionMower) ? futurePositionMower : this); }
public string Run(string sequenceChar) { //TODO : check that sequence char is valid string[] splittedInput = ReadLines(sequenceChar); Dictionary <PositionMower, Command[]> commandsOnMowers = SequenceCharParser.ParseCommandOnMower(splittedInput); Lawn lawn = SequenceCharParser.ParseLawn(splittedInput[0], commandsOnMowers.Keys.ToArray()); IEnumerable <PositionMower> newPositionMowers = ApplyCommands(commandsOnMowers, lawn); return(BuildOutputPosition(newPositionMowers)); }
private static IEnumerable <PositionMower> ApplyCommands(Dictionary <PositionMower, Command[]> commandsOnMowers, Lawn lawn) { foreach (PositionMower positionMower in commandsOnMowers.Keys) { yield return(commandsOnMowers[positionMower].Aggregate(positionMower, lawn.ApplyCommand)); } }