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
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 or board.variant == GIVEAWAYCHESS: if pieceCount(lboard, lboard.color) == 0: if board.color == WHITE: status = WHITEWON else: status = BLACKWON return status, WON_NOMATERIAL elif board.variant == HORDECHESS: if pieceCount(lboard, lboard.color) == 0 and board.color == WHITE: status = BLACKWON return status, WON_WIPEOUT elif board.variant == ATOMICCHESS: if lboard.boards[board.color][KING] == 0: if board.color == WHITE: status = BLACKWON else: status = WHITEWON return status, WON_KINGEXPLODE elif board.variant == KINGOFTHEHILLCHESS: if testKingInCenter(lboard): if board.color == BLACK: status = WHITEWON else: status = BLACKWON return status, WON_KINGINCENTER elif board.variant == THREECHECKCHESS: if checkCount(lboard) == 3: if board.color == BLACK: status = WHITEWON else: status = BLACKWON return status, WON_THREECHECK elif board.variant == RACINGKINGSCHESS: if testKingInEightRow(lboard): if board.color == BLACK: status = WHITEWON else: status = BLACKWON return status, WON_KINGINEIGHTROW 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 or board.variant == GIVEAWAYCHESS: 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