public bool[,] PossibleMoves(ChessPosition sourceChessPosition) { Position sourcePosition = sourceChessPosition.ToPosition(); ValidateSourcePosition(sourcePosition); return(Board.GetPiece(sourcePosition).PossibleMoves()); }
public ChessPiece PerformChessMove(ChessPosition sourceChessPosition, ChessPosition targetChessPosition) { Position sourcePosition = sourceChessPosition.ToPosition(); Position targetPosition = targetChessPosition.ToPosition(); ValidateSourcePosition(sourcePosition); ValidateTargetPosition(sourcePosition, targetPosition); Piece capturedPiece = MakeMove(sourcePosition, targetPosition); if (TestCheck(CurrentPlayer)) { UndoMove(sourcePosition, targetPosition, capturedPiece); throw new ChessException("You cant put yourself in check.\n"); } ChessPiece movedPiece = (ChessPiece)Board.GetPiece(targetPosition); //SpecialMove Promotion Promoted = null; if (movedPiece is Pawn) { if ((movedPiece.Color == Color.White && targetPosition.Row == 0) || (movedPiece.Color == Color.Black && targetPosition.Row == 7)) { Promoted = (ChessPiece)Board.GetPiece(targetPosition); Promoted = ReplacePromotedPiece("Q"); } } Check = ((TestCheck(OpponentColor(CurrentPlayer))) ? true : false); if (TestCheckMate(OpponentColor(CurrentPlayer))) { CheckMate = true; } else { NextTurn(); } //SpecialMove EnPassant if (movedPiece is Pawn && (targetPosition.Row == sourcePosition.Row - 2 || targetPosition.Row == sourcePosition.Row + 2)) { EnPassantVulnerable = movedPiece; } else { EnPassantVulnerable = null; } return((ChessPiece)capturedPiece); }