Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Dogopher
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gabriel Santamaria
Dogopher
Commits
53fa2f5a
Unverified
Commit
53fa2f5a
authored
8 months ago
by
Gabriel Santamaria
Browse files
Options
Downloads
Patches
Plain Diff
Fixing a little problem in playouts
parent
f7198d82
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
game/strategy.py
+17
-17
17 additions, 17 deletions
game/strategy.py
with
17 additions
and
17 deletions
game/strategy.py
+
17
−
17
View file @
53fa2f5a
...
...
@@ -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_firs
t
_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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment