Exemple #1
0
        internal bool canThisLocationBeCapture(ChessBoard board, Location tryToMoveTo, colors captureingSideColor)     //gonna be used to check if a move checks our king, and also to try and check the enemy's king
        {
            List <ChessPiece> captureingList = captureingSideColor == colors.WHITE ? board.whitesAlive : board.blacksAlive;

            foreach (ChessPiece piece in captureingList)
            {
                if (piece is Pawn)       //simulate a situtation only for pawn captureing a piece
                {
                    Pawn pawn = piece.Clone() as Pawn;
                    pawn.hasDoneFirstMove = true;
                    bool legalColForCapture = (tryToMoveTo.Col == pawn.CurrentLocation.Col - 1 || tryToMoveTo.Col == pawn.CurrentLocation.Col + 1);
                    if (pawn.isLegalRow(tryToMoveTo.Row) && legalColForCapture)
                    {
                        return(true);
                    }
                }
                else if (piece.isLegal(board, tryToMoveTo))
                {
                    return(true);
                }
            }
            return(false);
        }