private void MoveRobot(Movements movement) { switch (movement.Direction) { case Direction.North: Position = new Position(Position.X, Position.Y + 1); break; case Direction.South: Position = new Position(Position.X, Position.Y - 1); break; case Direction.East: Position = new Position(Position.X + 1, Position.Y); break; case Direction.West: Position = new Position(Position.X - 1, Position.Y); break; } if (!UniqueLocationsVisited.Contains(Position)) { UniqueLocationsVisited.Add(Position); } }
private static Movements SetMovement(string input) { var robotMovement = new Movements(); var movementString = input.Split(null); if (movementString.Length <= 1) { return(robotMovement); } switch (movementString[0]) { case "N": robotMovement.Direction = Direction.North; break; case "S": robotMovement.Direction = Direction.South; break; case "E": robotMovement.Direction = Direction.East; break; case "W": robotMovement.Direction = Direction.West; break; } var stepCount = int.Parse(movementString[1]); if (stepCount > 99999) { robotMovement.StepCount = 99999; } else if (stepCount < 1) { robotMovement.StepCount = 1; } else { robotMovement.StepCount = stepCount; } return(robotMovement); }