tweaked mcts score evaluation: considered steps when scoring the board
This commit is contained in:
2
eval.py
2
eval.py
@@ -177,6 +177,6 @@ def score_stockfish(board: chess.Board) -> chess.engine.PovScore:
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
engine = chess.engine.SimpleEngine.popen_uci("./stockfish/stockfish-ubuntu-x86-64-avx2")
|
engine = chess.engine.SimpleEngine.popen_uci("./stockfish/stockfish-ubuntu-x86-64-avx2")
|
||||||
info = engine.analyse(board, chess.engine.Limit(depth=20))
|
info = engine.analyse(board, chess.engine.Limit(depth=2))
|
||||||
engine.quit()
|
engine.quit()
|
||||||
return info["score"]
|
return info["score"]
|
||||||
|
|||||||
8
main.py
8
main.py
@@ -5,7 +5,7 @@ import engine
|
|||||||
import eval
|
import eval
|
||||||
|
|
||||||
|
|
||||||
def test_mcts(seed):
|
def test_mcts():
|
||||||
fools_mate = "rnbqkbnr/pppp1ppp/4p3/8/5PP1/8/PPPPP2P/RNBQKBNR b KQkq f3 0 2"
|
fools_mate = "rnbqkbnr/pppp1ppp/4p3/8/5PP1/8/PPPPP2P/RNBQKBNR b KQkq f3 0 2"
|
||||||
board = chess.Board(fools_mate)
|
board = chess.Board(fools_mate)
|
||||||
mcts_root = MCTSNode(board)
|
mcts_root = MCTSNode(board)
|
||||||
@@ -15,7 +15,7 @@ def test_mcts(seed):
|
|||||||
print("move (mcts):", c.move, " with score:", c.score)
|
print("move (mcts):", c.move, " with score:", c.score)
|
||||||
|
|
||||||
|
|
||||||
def test_stockfish(seed):
|
def test_stockfish():
|
||||||
fools_mate = "rnbqkbnr/pppp1ppp/4p3/8/5PP1/8/PPPPP2P/RNBQKBNR b KQkq f3 0 2"
|
fools_mate = "rnbqkbnr/pppp1ppp/4p3/8/5PP1/8/PPPPP2P/RNBQKBNR b KQkq f3 0 2"
|
||||||
board = chess.Board(fools_mate)
|
board = chess.Board(fools_mate)
|
||||||
moves = {}
|
moves = {}
|
||||||
@@ -37,8 +37,8 @@ def analyze_results(moves: dict):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
test_mcts(0)
|
test_mcts()
|
||||||
test_stockfish(0)
|
test_stockfish()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
6
mcts.py
6
mcts.py
@@ -30,21 +30,23 @@ class MCTSNode:
|
|||||||
self.children.append(child_node)
|
self.children.append(child_node)
|
||||||
return child_node
|
return child_node
|
||||||
|
|
||||||
def _rollout(self, rollout_depth: int = 100) -> float:
|
def _rollout(self, rollout_depth: int = 20) -> int:
|
||||||
"""
|
"""
|
||||||
Rolls out the node by simulating a game for a given depth.
|
Rolls out the node by simulating a game for a given depth.
|
||||||
Sometimes this step is called 'simulation' or 'playout'.
|
Sometimes this step is called 'simulation' or 'playout'.
|
||||||
:return: the score of the rolled out game
|
:return: the score of the rolled out game
|
||||||
"""
|
"""
|
||||||
copied_board = self.board.copy()
|
copied_board = self.board.copy()
|
||||||
|
steps = 1
|
||||||
for i in range(rollout_depth):
|
for i in range(rollout_depth):
|
||||||
if copied_board.is_game_over():
|
if copied_board.is_game_over():
|
||||||
break
|
break
|
||||||
|
|
||||||
m = engine.pick_move(copied_board)
|
m = engine.pick_move(copied_board)
|
||||||
copied_board.push(m)
|
copied_board.push(m)
|
||||||
|
steps += 1
|
||||||
|
|
||||||
return eval.score_manual(copied_board)
|
return eval.score_manual(copied_board) // steps
|
||||||
|
|
||||||
def _backpropagate(self, score: float) -> None:
|
def _backpropagate(self, score: float) -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user