Create a new ClassicMcts, which is split into two files
This commit is contained in:
24
chesspp/mcts/classic_mcts_v2.py
Normal file
24
chesspp/mcts/classic_mcts_v2.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import chess
|
||||
from chesspp.i_strategy import IStrategy
|
||||
from chesspp.mcts.classic_mcts_node_v2 import ClassicMctsNodeV2
|
||||
|
||||
|
||||
class ClassicMctsV2:
|
||||
def __init__(self, board: chess.Board, color: chess.Color, strategy: IStrategy):
|
||||
self.board = board
|
||||
self.color = color
|
||||
self.strategy = strategy
|
||||
self.root = ClassicMctsNodeV2(board, color, strategy)
|
||||
|
||||
def build_tree(self, samples: int = 1000):
|
||||
"""
|
||||
Runs the MCTS with the given number of samples
|
||||
:param samples: number of simulations
|
||||
:return: best node containing the best move
|
||||
"""
|
||||
for i in range(samples):
|
||||
node = self.root._select_leaf()
|
||||
score = node._rollout()
|
||||
node._backpropagate(score)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user