Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
hanabi
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
9
Issues
9
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
IGGI students
hanabi
Commits
f406081a
Commit
f406081a
authored
Apr 04, 2019
by
Joseph Walton-Rivers
🐦
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ensure that getUCTNode is handled correctly on unexpanded nodes
parent
0e4b6fc5
Pipeline
#2152
passed with stages
in 2 minutes and 48 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
3 deletions
+27
-3
src/main/java/com/fossgalaxy/games/fireworks/ai/mcts/MCTS.java
...ain/java/com/fossgalaxy/games/fireworks/ai/mcts/MCTS.java
+1
-0
src/main/java/com/fossgalaxy/games/fireworks/ai/mcts/MCTSNode.java
...java/com/fossgalaxy/games/fireworks/ai/mcts/MCTSNode.java
+26
-3
No files found.
src/main/java/com/fossgalaxy/games/fireworks/ai/mcts/MCTS.java
View file @
f406081a
...
...
@@ -25,6 +25,7 @@ public class MCTS implements Agent {
public
static
final
int
DEFAULT_ROLLOUT_DEPTH
=
18
;
public
static
final
int
DEFAULT_TREE_DEPTH_MUL
=
1
;
public
static
final
int
NO_LIMIT
=
100
;
protected
static
final
boolean
OLD_UCT_BEHAVIOUR
=
false
;
protected
final
int
roundLength
;
protected
final
int
rolloutDepth
;
...
...
src/main/java/com/fossgalaxy/games/fireworks/ai/mcts/MCTSNode.java
View file @
f406081a
...
...
@@ -9,7 +9,9 @@ import org.slf4j.LoggerFactory;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.stream.Collectors
;
...
...
@@ -36,7 +38,9 @@ public class MCTSNode {
private
double
score
;
private
int
visits
;
private
int
parentWasVisitedAndIWasLegal
;
private
int
parentWasVisitedAndIWasLegalOld
;
protected
Map
<
Action
,
Integer
>
legalChildVisits
;
protected
final
StatsSummary
rolloutScores
;
protected
final
StatsSummary
rolloutMoves
;
...
...
@@ -73,6 +77,8 @@ public class MCTSNode {
this
.
random
=
new
Random
();
this
.
depth
=
(
parent
==
null
)
?
0
:
parent
.
depth
+
1
;
this
.
legalChildVisits
=
new
HashMap
<>();
this
.
rolloutScores
=
new
BasicStats
();
this
.
rolloutMoves
=
new
BasicStats
();
...
...
@@ -89,7 +95,8 @@ public class MCTSNode {
return
0
;
}
return
((
score
/
MAX_SCORE
)
/
visits
)
+
(
expConst
*
Math
.
sqrt
(
Math
.
log
(
parentWasVisitedAndIWasLegal
)
/
visits
));
int
legalVisits
=
MCTS
.
OLD_UCT_BEHAVIOUR
?
parentWasVisitedAndIWasLegalOld
:
parent
.
legalChildVisits
.
get
(
moveToState
);
return
((
score
/
MAX_SCORE
)
/
visits
)
+
(
expConst
*
Math
.
sqrt
(
Math
.
log
(
legalVisits
)
/
visits
));
}
public
List
<
MCTSNode
>
getChildren
()
{
...
...
@@ -123,7 +130,10 @@ public class MCTSNode {
if
(!
moveToMake
.
isLegal
(
child
.
agentId
,
state
))
{
continue
;
}
child
.
parentWasVisitedAndIWasLegal
++;
child
.
parentWasVisitedAndIWasLegalOld
++;
updateVisitCount
(
moveToMake
);
double
childScore
=
child
.
getUCTValue
()
+
(
random
.
nextDouble
()
*
EPSILON
);
if
(
childScore
>
bestScore
)
{
...
...
@@ -131,9 +141,22 @@ public class MCTSNode {
bestChild
=
child
;
}
}
//now, update all children we haven't expanded yet, but we could have done
int
nextPlayer
=
(
getAgent
()
+
1
)
%
state
.
getPlayerCount
();
for
(
Action
unexpandedAction
:
allUnexpandedActions
)
{
if
(
unexpandedAction
.
isLegal
(
nextPlayer
,
state
))
{
updateVisitCount
(
unexpandedAction
);
}
}
return
bestChild
;
}
protected
void
updateVisitCount
(
Action
action
)
{
int
current
=
legalChildVisits
.
getOrDefault
(
action
,
0
);
legalChildVisits
.
put
(
action
,
current
+
1
);
}
public
int
getAgent
()
{
return
agentId
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment