Esempio n. 1
0
def find_puzzle_candidates(game: Game, scan_depth=SCAN_DEPTH) -> List[Puzzle]:
    """ finds puzzle candidates from a chess game 
    """
    log(Color.DIM, "Scanning game for puzzles (depth: %d)..." % scan_depth)
    prev_score = Cp(0)
    puzzles = []
    i = 0
    node = game
    while not node.is_end():
        next_node = node.variation(0)
        next_board = next_node.board()
        cur_score = AnalysisEngine.best_move(next_board, scan_depth).score
        board = node.board()
        highlight_move = False
        if should_investigate(prev_score, cur_score, board):
            highlight_move = True
            puzzle = Puzzle(
                board,
                next_node.move,
            )
            puzzles.append(puzzle)
        log_move(board, next_node.move, cur_score, highlight=highlight_move)
        prev_score = cur_score
        node = next_node
        i += 1
    return puzzles
 def _calculate_best_move(self, depth):
     """ Find the best move from board position using multipv 1
     """
     log(Color.BLACK, "Evaluating best move (depth %d)..." % depth)
     best_move = AnalysisEngine.best_move(self.board, depth)
     self.best_move = best_move.move
     self.score = best_move.score
     if self._num_legal_moves() == 1:
         self.candidate_moves = [best_move]
     self._log_move(self.best_move, self.score)
Esempio n. 3
0
 def _analyze_best_initial_move(self, depth) -> Move:
     log(Color.BLACK, "Evaluating best initial move (depth %d)..." % depth)
     best_move = AnalysisEngine.best_move(self.initial_board, depth)
     if best_move.move:
         self.analyzed_moves.append(best_move)
         log_move(self.initial_board,
                  best_move.move,
                  best_move.score,
                  show_uci=True)
     self.initial_score = best_move.score
     return best_move.move