Beispiel #1
0
def isClaimableDraw (board):
    lboard = board.board
    if lboard.repetitionCount () >= 3:
        return True
    if ldraw.testFifty (lboard):
        return True
    return False
Beispiel #2
0
def isClaimableDraw(board):
    lboard = board.board
    if ldraw.repetitionCount(lboard) >= 3:
        return True
    if ldraw.testFifty(lboard):
        return True
    return False
Beispiel #3
0
def getStatus(board):

    lboard = board.board

    if board.variant == LOSERSCHESS:
        if testKingOnly(lboard):
            if board.color == WHITE:
                status = WHITEWON
            else:
                status = BLACKWON
            return status, WON_NOMATERIAL
    else:
        if ldraw.testMaterial(lboard):
            return DRAW, DRAW_INSUFFICIENT

    if ldraw.repetitionCount(lboard) >= 3:
        return DRAW, DRAW_REPITITION

    if ldraw.testFifty(lboard):
        return DRAW, DRAW_50MOVES

    board_clone = lboard.clone()
    for move in lmovegen.genAllMoves(board_clone):
        board_clone.applyMove(move)
        if board_clone.opIsChecked():
            board_clone.popMove()
            continue
        board_clone.popMove()
        return RUNNING, UNKNOWN_REASON

    if lboard.isChecked():
        if board.variant == LOSERSCHESS:
            if board.color == WHITE:
                status = WHITEWON
            else:
                status = BLACKWON
        else:
            if board.color == WHITE:
                status = BLACKWON
            else:
                status = WHITEWON
        return status, WON_MATE

    if board.variant == LOSERSCHESS:
        if board.color == WHITE:
            status = WHITEWON
        else:
            status = BLACKWON
        return status, DRAW_STALEMATE
    else:
        return DRAW, DRAW_STALEMATE
Beispiel #4
0
def getStatus (board):
    lboard = board.board

    if board.variant == LOSERSCHESS:
        if testKingOnly(lboard):
            if board.color == WHITE:
                status = WHITEWON
            else:
                status = BLACKWON
            return status, WON_NOMATERIAL
    elif board.variant == SUICIDECHESS:
        if pieceCount(lboard, lboard.color) == 0:
            if board.color == WHITE:
                status = WHITEWON
            else:
                status = BLACKWON
            return status, WON_NOMATERIAL
    elif board.variant == ATOMICCHESS:
        if lboard.boards[board.color][KING] == 0:
            if board.color == WHITE:
                status = BLACKWON
            else:
                status = WHITEWON
            return status, WON_KINGEXPLODE
    else:
        if ldraw.testMaterial (lboard):
            return DRAW, DRAW_INSUFFICIENT
    
    hasMove = False
    for move in lmovegen.genAllMoves (lboard):
        if board.variant == ATOMICCHESS:
            if kingExplode(lboard, move, 1-board.color) and not kingExplode(lboard, move, board.color):
                hasMove = True
                break
            elif kingExplode(lboard, move, board.color):
                continue
        lboard.applyMove(move)
        if lboard.opIsChecked():
            lboard.popMove()
            continue
        hasMove = True
        lboard.popMove()
        break

    if not hasMove:
        if lboard.isChecked():
            if board.variant == LOSERSCHESS:
                if board.color == WHITE:
                    status = WHITEWON
                else:
                    status = BLACKWON
            else:
                if board.color == WHITE:
                    status = BLACKWON
                else:
                    status = WHITEWON
            return status, WON_MATE
        else:
            if board.variant == LOSERSCHESS:
                if board.color == WHITE:
                    status = WHITEWON
                else:
                    status = BLACKWON
                return status, DRAW_STALEMATE
            elif board.variant == SUICIDECHESS:
                if pieceCount(lboard, WHITE) == pieceCount(lboard, BLACK):
                    return status, DRAW_EQUALMATERIAL
                else:
                    if board.color == WHITE and pieceCount(lboard, WHITE) < pieceCount(lboard, BLACK):
                        status = WHITEWON
                    else:
                        status = BLACKWON
                    return status, WON_LESSMATERIAL
            else:
                return DRAW, DRAW_STALEMATE

    if lboard.repetitionCount () >= 3:
        return DRAW, DRAW_REPITITION
    
    if ldraw.testFifty (lboard):
        return DRAW, DRAW_50MOVES

    return RUNNING, UNKNOWN_REASON