Esempio n. 1
0
def testMaterial(board):
    """ Tests if no players are able to win the game from the current
        position """

    whiteBoards = board.boards[WHITE]
    blackBoards = board.boards[BLACK]

    if bitLength(whiteBoards[PAWN]) or bitLength(blackBoards[PAWN]):
        return False

    if bitLength(whiteBoards[QUEEN]) or bitLength(blackBoards[QUEEN]):
        return False

    wn = bitLength(whiteBoards[KNIGHT])
    wb = bitLength(whiteBoards[BISHOP])
    wr = bitLength(whiteBoards[ROOK])
    bn = bitLength(blackBoards[KNIGHT])
    bb = bitLength(blackBoards[BISHOP])
    br = bitLength(blackBoards[ROOK])

    if (wn, wb, wr, 0, bn, bb, br, 0) in drawSet:
        return True

    # Tests KBKB. Draw if bishops are of same color
    if not wn + wr + bn + wr and wb == 1 and bb == 1:
        if whiteBoards[BISHOP] & BLACK_SQUARES and True != \
           blackBoards[BISHOP] & BLACK_SQUARES and True:
            return True
Esempio n. 2
0
def testMaterial (board):
    """ Tests if no players are able to win the game from the current
        position """
    
    whiteBoards = board.boards[WHITE]
    blackBoards = board.boards[BLACK]
    
    if bitLength(whiteBoards[QUEEN]) > 0 or bitLength(whiteBoards[ROOK]) or \
            bitLength(blackBoards[QUEEN]) > 0 or bitLength(blackBoards[ROOK]):
        return False
    
    wp = bitLength(whiteBoards[PAWN])
    bp = bitLength(blackBoards[PAWN])
    if wp > 0 or bp > 0:
        return False
    
    wn = bitLength(whiteBoards[KNIGHT])
    wb = bitLength(whiteBoards[BISHOP])
    bn = bitLength(blackBoards[KNIGHT])
    bb = bitLength(blackBoards[BISHOP])
    
    # Tests: KK, KBK, KKB, KNK, KKN
    if wn + wb + bn + bb <= 1:
        return True
    
    # Tests KBKB
    if wn == 0 and bn == 0 and wb == 1 and bb == 1:
        # Draw if bishops are of same color
        if (whiteBoards[BISHOP] & BLACK_SQUARES and BLACK or WHITE) == \
                (blackBoards[BISHOP] & BLACK_SQUARES and BLACK or WHITE):
            return True
Esempio n. 3
0
def testMaterial (board):
    """ Tests if no players are able to win the game from the current
        position """
    
    whiteBoards = board.boards[WHITE]
    blackBoards = board.boards[BLACK]
    
    if bitLength(whiteBoards[PAWN]) or bitLength(blackBoards[PAWN]):
        return False
    
    if bitLength(whiteBoards[QUEEN]) or bitLength(blackBoards[QUEEN]):
        return False
    
    wn = bitLength(whiteBoards[KNIGHT])
    wb = bitLength(whiteBoards[BISHOP])
    wr = bitLength(whiteBoards[ROOK])
    bn = bitLength(blackBoards[KNIGHT])
    bb = bitLength(blackBoards[BISHOP])
    br = bitLength(blackBoards[ROOK])
    
    if (wn, wb, wr, 0,   bn, bb, br, 0) in drawSet:
        return True
        
    # Tests KBKB. Draw if bishops are of same color
    if not wn + wr + bn + wr and wb == 1 and bb == 1:
        if whiteBoards[BISHOP] & BLACK_SQUARES and True != \
           blackBoards[BISHOP] & BLACK_SQUARES and True:
            return True
Esempio n. 4
0
def testPlayerMatingMaterial(board, color):
    """ Tests if given color has enough material to mate on board """

    boards = board.boards[color]

    if bitLength(boards[PAWN]) or bitLength(boards[QUEEN]) \
       or bitLength(boards[ROOK]) \
       or (bitLength(boards[KNIGHT]) + bitLength(boards[BISHOP]) > 1):
        return True
    return False
Esempio n. 5
0
def testPlayerMatingMaterial (board, color):
    """ Tests if given color has enough material to mate on board """

    boards = board.boards[color]
    
    if bitLength(boards[PAWN]) or bitLength(boards[QUEEN]) \
       or bitLength(boards[ROOK]) \
       or (bitLength(boards[KNIGHT]) + bitLength(boards[BISHOP]) > 1):
        return True
    return False