private bool IsRoverWithinPlateu(GridSize grid, Position position) //TODO: move to helper class { if (position.X > grid.Width || position.X < 0 || position.Y > grid.Height || position.Y < 0) { return(false); } return(true); }
public Position Move(GridSize plateuSize, Position position) { var initialPosition = position; switch (position.Cardinality) { case Cardinality.N: position.Y++; break; case Cardinality.E: position.X++; break; case Cardinality.S: position.Y--; break; case Cardinality.W: position.X--; break; default: throw new InvalidOperationException(); } if (!IsRoverWithinPlateu(plateuSize, position)) { //revert position change position.X = initialPosition.X; position.Y = initialPosition.Y; //log message } return(position); }