public Rover(string name, Plateau plateau, Position position) { _plateau = plateau; _movements = new List<Position>(); Name = name; Apply(position); }
private void Apply(Position position) { if (!_plateau.Contains(position)) { return; } _movements.Add(position); Position = position; }
public Position Left() { var position = new Position { X = X, Y = Y, Direction = Turn(-90) }; return position; }
public bool Contains(Position position) { if (position.X > Width) { return false; } if (position.Y > Height) { return false; } if (position.X < 0) { return false; } if (position.Y < 0) { return false; } return true; }
public Position Right() { var position = new Position { X = X, Y = Y, Direction = Turn(90) }; return position; }
public Position Move() { var position = new Position { Direction = Direction, Y = new Func<int>(() => { if (Direction == Direction.N) { return Y + 1; } if (Direction == Direction.S) { return Y - 1; } return Y; })(), X = new Func<int>(() => { if (Direction == Direction.E) { return X + 1; } if (Direction == Direction.W) { return X - 1; } return X; })() }; return position; }