public Piece ExecuteMoviment(Position origin, Position destination) { Piece piece = Board.removePieceFromPosition(origin); piece.IncrementMovementQuantity(); Piece capturedPiece = Board.removePieceFromPosition(destination); Board.SetPieceInPosition(piece, destination); if (capturedPiece != null) { capturedPieces.Add(capturedPiece); } // #Castle Kingside if (piece is King && destination.Column == origin.Column + 2) { Position originT = new Position(origin.Line, origin.Column + 3); Position destinationT = new Position(origin.Line, origin.Column + 1); Piece T = Board.removePieceFromPosition(originT); T.IncrementMovementQuantity(); Board.SetPieceInPosition(T, destinationT); } // #Castle Queenside if (piece is King && destination.Column == origin.Column - 2) { Position originT = new Position(origin.Line, origin.Column - 4); Position destinationT = new Position(origin.Line, origin.Column - 1); Piece T = Board.removePieceFromPosition(originT); T.IncrementMovementQuantity(); Board.SetPieceInPosition(T, destinationT); } // #jogadaespecial en passant if (piece is Pawn) { if (origin.Column != destination.Column && capturedPiece == null) { Position posP; if (piece.Color == Color.White) { posP = new Position(destination.Line + 1, destination.Column); } else { posP = new Position(destination.Line - 1, destination.Column); } capturedPiece = Board.removePieceFromPosition(posP); capturedPieces.Add(capturedPiece); } } return(capturedPiece); }
public void UndoMovement(Position origin, Position destination, Piece capturedPiece) { Piece piece = Board.removePieceFromPosition(destination); piece.DecrementMovementQuantity(); if (capturedPiece != null) { Board.SetPieceInPosition(capturedPiece, destination); capturedPieces.Remove(capturedPiece); } Board.SetPieceInPosition(piece, origin); // #Castle Kingside if (piece is King && destination.Column == origin.Column + 2) { Position originT = new Position(origin.Line, origin.Column + 3); Position destinationT = new Position(origin.Line, origin.Column + 1); Piece T = Board.removePieceFromPosition(destinationT); T.DecrementMovementQuantity(); Board.SetPieceInPosition(T, originT); } // #Castle Queenside if (piece is King && destination.Column == origin.Column - 2) { Position originT = new Position(origin.Line, origin.Column - 4); Position destinationT = new Position(origin.Line, origin.Column - 1); Piece T = Board.removePieceFromPosition(destinationT); T.DecrementMovementQuantity(); Board.SetPieceInPosition(T, originT); } // #en passant if (piece is Pawn) { if (origin.Column != destination.Column && capturedPiece == VulnerableEnPassant) { Piece pawn = Board.removePieceFromPosition(destination); Position posP; if (piece.Color == Color.White) { posP = new Position(3, destination.Column); } else { posP = new Position(4, destination.Column); } Board.SetPieceInPosition(pawn, posP); } } }
public void PerformeMove(Position origin, Position destination) { Piece capturedPiece = ExecuteMoviment(origin, destination); if (IsInCheck(CurrentPlayer)) { UndoMovement(origin, destination, capturedPiece); throw new BoardException("You cannot put yourself in check"); } Piece p = Board.piece(destination); // #promocao if (p is Pawn) { if ((p.Color == Color.White && destination.Line == 0) || (p.Color == Color.Black && destination.Line == 7)) { p = Board.removePieceFromPosition(destination); pieces.Remove(p); Piece queen = new Queen(Board, p.Color); Board.SetPieceInPosition(queen, destination); pieces.Add(queen); } } CheckMate = IsInCheck(Opponent(CurrentPlayer)); if (TestCheckMate(Opponent(CurrentPlayer))) { FinishedMatch = true; } else { Turn++; ChangePlayer(); } // #en passant if (p is Pawn && (destination.Line == origin.Line - 2 || destination.Line == origin.Line + 2)) { VulnerableEnPassant = p; } else { VulnerableEnPassant = null; } }
public void PutNewPiece(char column, int line, Piece piece) { Board.SetPieceInPosition(piece, new PositionChess(column, line).ToBoardPosition()); pieces.Add(piece); }