Skip to content
Snippets Groups Projects
Unverified Commit 53fa2f5a authored by Gabriel Santamaria's avatar Gabriel Santamaria
Browse files

Fixing a little problem in playouts

parent f7198d82
No related branches found
No related tags found
No related merge requests found
......@@ -155,7 +155,7 @@ class StrategyAlphaBeta(Strategy):
def get_first_move(self) -> Action:
"""
This function returns the first move for the Gopher game, calculated by the precompute_firs_move
This function returns the first move for the Gopher game, calculated by the precompute_first_move
It is meant to save the time wasted by the alphabeta when calculating the very first move of the game, which
takes a very long time because there are a lot of possibilities when the board is empty.
Therefore, the first move is calculated beforehand
......@@ -168,12 +168,12 @@ class StrategyAlphaBeta(Strategy):
def get_action(self, grid: HexGrid, ply: Player) -> Action:
self.current_state = grid
action = None
if self.rules.is_first_turn(grid) and isinstance(self.rules, Gopher):
action = self.get_first_move()
# action = None
# if self.rules.is_first_turn(grid) and isinstance(self.rules, Gopher):
# action = self.get_first_move()
if action is not None:
return action
# if action is not None:
# return action
return self.minmax(ply, -inf, inf, self.depth)[1]
......@@ -313,7 +313,7 @@ class MCTSStrategy(Strategy):
if res is not None:
action = res[1]
if action is None:
if action is None or action not in legals:
i = self.rng.choice(range(len(legals)), 1)[0]
action = legals[i]
......@@ -493,16 +493,6 @@ class MCTSStrategy(Strategy):
"""
Performs a training of the MCTS tree.
"""
# We need to re-init the see for the
# random number generators so that
# it's not always the same nodes expanded
# for each simulation accross the different
# processes
seed = random.SeedSequence(int.from_bytes(os.urandom(16), "big") * os.getpid())
rng = random.Generator(random.MT19937(seed))
self.rng = rng
root = self.root
node = self.__select(root)
self.__expand(node, self.rules)
......@@ -518,6 +508,16 @@ class MCTSStrategy(Strategy):
Args:
simulations: The number of simulations to run
"""
# We need to re-init the see for the
# random number generators so that
# it's not always the same nodes expanded
# for each simulation accross the different
# processes
seed = random.SeedSequence(int.from_bytes(os.urandom(16), "big") * os.getpid())
rng = random.Generator(random.MT19937(seed))
self.rng = rng
for _ in range(simulations):
self.__train()
return self.root
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment