public override void Move(MoveDirection dir) { Position to; switch (dir) { case MoveDirection.UpLeft: to = new Position(Pos.Row - 1, Pos.Col - 1); break; case MoveDirection.UpRight: to = new Position(Pos.Row - 1, Pos.Col + 1); break; case MoveDirection.DownLeft: to = new Position(Pos.Row + 1, Pos.Col - 1); break; case MoveDirection.DownRight: to = new Position(Pos.Row + 1, Pos.Col + 1); break; default: // Should cover all cases return; } if (!_board.IsValidPosition(to)) return; Move m = new Move(Pos, to); _board.Move(m); Pos = to; }
/// <summary> /// Move this piece with by the provided move. If the move is invalid, /// it will throw an InvalidMoveException /// </summary> /// <param name="move">The move to make</param> public override void Move(Move move) { if (!IsValidMove(move)) throw new InvalidMoveException(); _board.Move(move); Pos = move.To; }
protected override bool IsValidMove(Move move) { var rowDiff = Math.Abs(Pos.Row - move.To.Row); var colDiff = Math.Abs(Pos.Col - move.To.Col); var canDoMove = rowDiff == 1 && colDiff == 1; return canDoMove && _board.IsValidPosition(move.To) && _board.IsCellEmpty(move.To); }
protected override bool IsValidMove(Move move) { var rowDiff = move.To.Row - Pos.Row; var colDiff = Math.Abs(Pos.Col - move.To.Col); bool isUpperDiag = rowDiff == -1 && colDiff == 1; var piece = _board.GetCell(move.To); var emptyOrLarva = piece == null || piece is Larva; return isUpperDiag && emptyOrLarva && _board.IsValidPosition(move.To); }
public void Move(Move m) { var cell = GetCell(m.From); SetCell(m.From, ' '); SetCell(m.To, cell); }
private Bird GetBirdToMove(Move move) { foreach (var bird in _birds) { if (bird.Pos == move.From) return bird; } throw new InvalidMoveException(); }