Exemplo n.º 1
0
    def sanitizeMove(self, moves, history, whiteKing, whiteQueen, whiteBishop,
                     whiteKnight, whiteRook, whitePawn, blackKing, blackQueen,
                     blackBishop, blackKnight, blackRook, blackPawn,
                     whiteQueenCastle, whiteKingCastle, blackQueenCastle,
                     blackKingCastle, whiteTurn):
        Moves = self.Moves

        moves = moves.split()
        li = []
        for i in range(len(moves)):
            currentMove = moves[i]
            #white pieces
            tempWhiteKing = Moves.makeMove(whiteKing, currentMove, "K")
            tempWhiteQueen = Moves.makeMove(whiteQueen, currentMove, "Q")
            tempWhiteBishop = Moves.makeMove(whiteBishop, currentMove, "B")
            tempWhiteKnight = Moves.makeMove(whiteKnight, currentMove, "H")
            tempWhiteRook = Moves.makeMove(whiteRook, currentMove, "R")
            tempWhitePawn = Moves.makeMove(whitePawn, currentMove, "P")
            #if castling, make castling move
            if ("WL" in currentMove or "WR" in currentMove):
                tempWhiteKing, tempWhiteRook = Moves.makeCastlingMove(
                    whiteKing, whiteRook, currentMove)
            #black pieces
            tempBlackKing = Moves.makeMove(blackKing, currentMove, "k")
            tempBlackQueen = Moves.makeMove(blackQueen, currentMove, "q")
            tempBlackBishop = Moves.makeMove(blackBishop, currentMove, "b")
            tempBlackKnight = Moves.makeMove(blackKnight, currentMove, "h")
            tempBlackRook = Moves.makeMove(blackRook, currentMove, "r")
            tempBlackPawn = Moves.makeMove(blackPawn, currentMove, "p")
            if ("BL" in currentMove or "BR" in currentMove):
                tempBlackKing, tempBlackRook = Moves.makeCastlingMove(
                    blackKing, blackRook, currentMove)
            tempHistory = currentMove

            if (whiteTurn):
                if ((tempWhiteKing & Moves.whiteKing_illegalMoves(
                        tempWhiteKing, tempWhiteQueen, tempWhiteBishop,
                        tempWhiteKnight, tempWhiteRook, tempWhitePawn,
                        tempBlackKing, tempBlackQueen, tempBlackBishop,
                        tempBlackKnight, tempBlackRook, tempBlackPawn)) == 0):
                    li.append(currentMove)
            elif (not whiteTurn):
                if ((tempBlackKing & Moves.blackKing_illegalMoves(
                        tempWhiteKing, tempWhiteQueen, tempWhiteBishop,
                        tempWhiteKnight, tempWhiteRook, tempWhitePawn,
                        tempBlackKing, tempBlackQueen, tempBlackBishop,
                        tempBlackKnight, tempBlackRook, tempBlackPawn)) == 0):
                    li.append(currentMove)
        return li
Exemplo n.º 2
0
    def getAllCurrentLegalMoves(self, whiteTurn):
        Moves = self.Moves

        if (whiteTurn):
            moves = Moves.white_legalMoves(
                self.history, self.whiteKing, self.whiteQueen,
                self.whiteBishop, self.whiteKnight, self.whiteRook,
                self.whitePawn, self.blackKing, self.blackQueen,
                self.blackBishop, self.blackKnight, self.blackRook,
                self.blackPawn, self.whiteQueenCastle, self.whiteKingCastle,
                self.blackQueenCastle, self.blackKingCastle)
        else:
            moves = Moves.black_legalMoves(
                self.history, self.whiteKing, self.whiteQueen,
                self.whiteBishop, self.whiteKnight, self.whiteRook,
                self.whitePawn, self.blackKing, self.blackQueen,
                self.blackBishop, self.blackKnight, self.blackRook,
                self.blackPawn, self.whiteQueenCastle, self.whiteKingCastle,
                self.blackQueenCastle, self.blackKingCastle)

        moves = moves.split()
        li = []
        for i in range(len(moves)):
            currentMove = moves[i]
            #white pieces
            tempWhiteKing = Moves.makeMove(self.whiteKing, currentMove, "K")
            tempWhiteQueen = Moves.makeMove(self.whiteQueen, currentMove, "Q")
            tempWhiteBishop = Moves.makeMove(self.whiteBishop, currentMove,
                                             "B")
            tempWhiteKnight = Moves.makeMove(self.whiteKnight, currentMove,
                                             "H")
            tempWhiteRook = Moves.makeMove(self.whiteRook, currentMove, "R")
            tempWhitePawn = Moves.makeMove(self.whitePawn, currentMove, "P")
            #if castling, make castling move
            if ("WL" in currentMove or "WR" in currentMove):
                tempWhiteKing, tempWhiteRook = Moves.makeCastlingMove(
                    self.whiteKing, self.whiteRook, currentMove)
            #black pieces
            tempBlackKing = Moves.makeMove(self.blackKing, currentMove, "k")
            tempBlackQueen = Moves.makeMove(self.blackQueen, currentMove, "q")
            tempBlackBishop = Moves.makeMove(self.blackBishop, currentMove,
                                             "b")
            tempBlackKnight = Moves.makeMove(self.blackKnight, currentMove,
                                             "h")
            tempBlackRook = Moves.makeMove(self.blackRook, currentMove, "r")
            tempBlackPawn = Moves.makeMove(self.blackPawn, currentMove, "p")
            if ("BL" in currentMove or "BR" in currentMove):
                tempBlackKing, tempBlackRook = Moves.makeCastlingMove(
                    self.blackKing, self.blackRook, currentMove)
            tempHistory = currentMove

            if (whiteTurn):
                if ((tempWhiteKing & Moves.whiteKing_illegalMoves(
                        tempWhiteKing, tempWhiteQueen, tempWhiteBishop,
                        tempWhiteKnight, tempWhiteRook, tempWhitePawn,
                        tempBlackKing, tempBlackQueen, tempBlackBishop,
                        tempBlackKnight, tempBlackRook, tempBlackPawn)) == 0):
                    li.append(currentMove)
            elif (not whiteTurn):
                if ((tempBlackKing & Moves.blackKing_illegalMoves(
                        tempWhiteKing, tempWhiteQueen, tempWhiteBishop,
                        tempWhiteKnight, tempWhiteRook, tempWhitePawn,
                        tempBlackKing, tempBlackQueen, tempBlackBishop,
                        tempBlackKnight, tempBlackRook, tempBlackPawn)) == 0):
                    li.append(currentMove)

        self.currentAllLegalMoves = li