aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorMatt Strapp <strap012@umn.edu>2021-05-02 14:17:58 -0500
committerMatt Strapp <strap012@umn.edu>2021-05-02 14:17:58 -0500
commit8ca72f6ddc9f5653b68ce9300085eefb868a31f5 (patch)
tree6bf5e4a4d77ecea87194a4e09bd9280e88363fbb /python
parentNew, shiny data (diff)
downloadcsci4511w-8ca72f6ddc9f5653b68ce9300085eefb868a31f5.tar
csci4511w-8ca72f6ddc9f5653b68ce9300085eefb868a31f5.tar.gz
csci4511w-8ca72f6ddc9f5653b68ce9300085eefb868a31f5.tar.bz2
csci4511w-8ca72f6ddc9f5653b68ce9300085eefb868a31f5.tar.lz
csci4511w-8ca72f6ddc9f5653b68ce9300085eefb868a31f5.tar.xz
csci4511w-8ca72f6ddc9f5653b68ce9300085eefb868a31f5.tar.zst
csci4511w-8ca72f6ddc9f5653b68ce9300085eefb868a31f5.zip
Fix MCTS
Diffstat (limited to 'python')
-rw-r--r--python/MCTS.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/python/MCTS.py b/python/MCTS.py
index 91cd41c..fbddceb 100644
--- a/python/MCTS.py
+++ b/python/MCTS.py
@@ -7,6 +7,7 @@ from GameState import GameState
# Based on https://github.com/DieterBuys/mcts-player/
+
class GameController(object):
def get_next_move(self, state):
# when you get a new move, it is assumed that the game is not ended yet
@@ -21,7 +22,6 @@ class MCTSNode(object):
"""
def __init__(self, state, parent=None, move=None):
-
self.parent = parent
self.move = move
self.state = state
@@ -37,7 +37,7 @@ class MCTSNode(object):
# to the sum of its children's plays
def ucb(child):
win_ratio = child.score / child.plays \
- + math.sqrt(2 * math.log(self.plays) / child.plays)
+ + math.sqrt(2 * math.log(self.plays) / child.plays)
return win_ratio
return max(self.children, key=ucb)
@@ -109,7 +109,7 @@ class MCTSGameController(GameController):
move = choice(tuple(node.pending_moves))
return node.expand_move(move)
- def simulate(self, state, max_iterations=2000):
+ def simulate(self, state, max_iterations=1000):
state = deepcopy(state)
move = state.get_random_move()
@@ -129,7 +129,7 @@ class MCTSGameController(GameController):
node.score += node.get_score(result)
node = node.parent
- def get_next_move(self, state, time_allowed=2.0):
+ def get_next_move(self, state, time_allowed=1.0):
super(MCTSGameController, self).get_next_move(state)
self.root_node = MCTSNode(state)