def cook_mate(engine: SimpleEngine, node: ChildNode, 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.debug( "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
def cook_mate(engine: SimpleEngine, node: ChildNode, winner: Color) -> Optional[List[Move]]: board = node.board() if board.is_game_over(): return [] if board.turn == winner: pair = get_next_pair(engine, node, winner) if not pair: return None if pair.best.score < mate_soon: logger.debug("Best move is not a mate, we're probably not searching deep enough") return None move = pair.best.move else: next = get_next_move(engine, node, mate_defense_limit) if not next: return None move = next follow_up = cook_mate(engine, node.add_main_variation(move), winner) if follow_up is None: return None return [move] + follow_up
def cook_advantage(engine: SimpleEngine, node: ChildNode, winner: Color) -> Optional[List[NextMovePair]]: if node.board().is_repetition(2): logger.debug("Found repetition, canceling") return None next = get_next_move(engine, node, winner) if not next: logger.debug("No next move") return [] if next.best.score.is_mate(): logger.debug("Expected advantage, got mate?!") return None if next.best.score < Cp(200): logger.debug("Not winning enough, aborting") 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
def cook_advantage(engine: SimpleEngine, node: ChildNode, winner: Color) -> Optional[List[NextMovePair]]: board = node.board() if board.is_repetition(2): logger.debug("Found repetition, canceling") return None pair = get_next_pair(engine, node, winner) if not pair: return [] if pair.best.score < Cp(200): logger.debug("Not winning enough, aborting") return None follow_up = cook_advantage(engine, node.add_main_variation(pair.best.move), winner) if follow_up is None: return None return [pair] + follow_up