Esempio n. 1
0
def cook_advantage(engine: SimpleEngine, node: GameNode, winner: Color) -> Optional[List[NextMovePair]]:

    is_capture = "x" in node.san() # monkaS
    up_in_material = is_up_in_material(node.board(), winner)

    if node.board().is_repetition(2):
        logger.info("Found repetition, canceling")
        return None

    # if not is_capture and up_in_material and len(node.board().checkers()) == 0:
    #     logger.info("Not a capture and we're up in material, end of the line")
    #     return []

    next = get_next_move(engine, node, winner)

    if not next:
        logger.debug("No next move")
        return []

    if next.best.score.is_mate():
        logger.info("Expected advantage, got mate?!")
        return None

    follow_up = cook_advantage(engine, node.add_main_variation(next.best.move), winner)

    if follow_up is None:
        return None

    return [next] + follow_up
Esempio n. 2
0
def cook_advantage(engine: SimpleEngine, node: GameNode,
                   winner: Color) -> Optional[List[Move]]:
    """
    Recursively calculate advantage solution
    """

    best_move, second_move = get_two_best_moves(engine, node.board(), winner)

    if node.board().turn == winner:
        logger.debug("Getting only advantage move...")

        if best_move.score < juicy_advantage:
            logger.info(
                "Best move is not a juicy advantage, we're probably not searching deep enough"
            )
            return None

        if second_move is not None and second_move.score > Cp(-300):
            logger.debug("Second best move is not terrible")
            return None

    else:
        logger.debug("Getting defensive move...")

        if best_move.score.is_mate():
            logger.info("Expected advantage, got mate?!")
            return None

        if second_move is not None:
            much_worse = second_move.score < Mate(2)
            if not much_worse:
                logger.info("A second defensive move is not that worse")
                return None

    next_moves = cook_advantage(engine,
                                node.add_main_variation(best_move.move),
                                winner)

    if next_moves is None:
        return None

    return [best_move.move] + next_moves
Esempio n. 3
0
def cook_mate(engine: SimpleEngine, node: GameNode,
              winner: Color) -> Optional[List[Move]]:
    """
    Recursively calculate mate solution
    """

    if node.board().is_game_over():
        return []

    best_move, second_move = get_two_best_moves(engine, node.board(), winner)

    if node.board().turn == winner:
        logger.debug("Getting only mate move...")

        if best_move.score < mate_soon:
            logger.info(
                "Best move is not a mate, we're probably not searching deep enough"
            )
            return None

        if second_move is not None and second_move.score > Cp(-300):
            logger.debug("Second best move is not terrible")
            return None

    else:
        logger.debug("Getting defensive move...")

        if best_move.score < Mate(1) and second_move is not None:
            much_worse = second_move.score == Mate(
                1) and best_move.score < Mate(3)
            if not much_worse:
                logger.info("A second defensive move is not that worse")
                return None

    next_moves = cook_mate(engine, node.add_main_variation(best_move.move),
                           winner)

    if next_moves is None:
        return None

    return [best_move.move] + next_moves
Esempio n. 4
0
def cook_mate(engine: SimpleEngine, node: GameNode, winner: Color) -> Optional[List[Move]]:

    if node.board().is_game_over():
        return []

    pair = get_next_move(engine, node, winner)

    if not pair:
        return None

    next = pair.best

    if next.score < mate_soon:
        logger.info("Best move is not a mate, we're probably not searching deep enough")
        return None

    follow_up = cook_mate(engine, node.add_main_variation(next.move), winner)

    if follow_up is None:
        return None

    return [next.move] + follow_up