MonteCarloUCT now plays most of a 9x9 game.
Sometimes attempts invalid move (suicide). See screenshots under bugreports.
This commit is contained in:
BIN
bugreports/bugreport09012012.png
Normal file
BIN
bugreports/bugreport09012012.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 404 KiB |
@@ -47,7 +47,7 @@ public class GoGame {
|
|||||||
} else if ("alphabeta".equals(policyName)) {
|
} else if ("alphabeta".equals(policyName)) {
|
||||||
return new AlphaBeta();
|
return new AlphaBeta();
|
||||||
} else if ("montecarlo".equals(policyName)) {
|
} else if ("montecarlo".equals(policyName)) {
|
||||||
return new MonteCarloUCT(new RandomMovePolicy(), 2000L);
|
return new MonteCarloUCT(new RandomMovePolicy(), 10000L);
|
||||||
} else {
|
} else {
|
||||||
LOGGER.info("Unable to create Policy for unsupported name: " + policyName);
|
LOGGER.info("Unable to create Policy for unsupported name: " + policyName);
|
||||||
System.exit(INVALID_MOVE_GENERATOR);
|
System.exit(INVALID_MOVE_GENERATOR);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import net.woodyfolsom.msproj.tree.GameTreeNode;
|
|||||||
import net.woodyfolsom.msproj.tree.MonteCarloProperties;
|
import net.woodyfolsom.msproj.tree.MonteCarloProperties;
|
||||||
|
|
||||||
public abstract class MonteCarlo implements Policy {
|
public abstract class MonteCarlo implements Policy {
|
||||||
protected static final int ROLLOUT_DEPTH_LIMIT = 20;
|
protected static final int ROLLOUT_DEPTH_LIMIT = 100;
|
||||||
|
|
||||||
protected int numStateEvaluations = 0;
|
protected int numStateEvaluations = 0;
|
||||||
protected Policy movePolicy;
|
protected Policy movePolicy;
|
||||||
|
|||||||
@@ -82,7 +82,11 @@ public class MonteCarloUCT extends MonteCarlo {
|
|||||||
}
|
}
|
||||||
nextGameState.playStone(player, action);
|
nextGameState.playStone(player, action);
|
||||||
List<GameTreeNode<MonteCarloProperties>> newChildren = new ArrayList<GameTreeNode<MonteCarloProperties>>();
|
List<GameTreeNode<MonteCarloProperties>> newChildren = new ArrayList<GameTreeNode<MonteCarloProperties>>();
|
||||||
newChildren.add(new GameTreeNode<MonteCarloProperties>(nextGameState,new MonteCarloProperties()));
|
GameTreeNode<MonteCarloProperties> newChild = new GameTreeNode<MonteCarloProperties>(nextGameState,new MonteCarloProperties());
|
||||||
|
|
||||||
|
newChildren.add(newChild);
|
||||||
|
node.addChild(action, newChild);
|
||||||
|
|
||||||
return newChildren;
|
return newChildren;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +112,8 @@ public class MonteCarloUCT extends MonteCarlo {
|
|||||||
}
|
}
|
||||||
} while (action != Action.NONE && rolloutDepth < ROLLOUT_DEPTH_LIMIT);
|
} while (action != Action.NONE && rolloutDepth < ROLLOUT_DEPTH_LIMIT);
|
||||||
|
|
||||||
|
numStateEvaluations++;
|
||||||
|
|
||||||
if (stateEvaluator.scoreGame(finalGameState).isWinner(player)) {
|
if (stateEvaluator.scoreGame(finalGameState).isWinner(player)) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import org.junit.Test;
|
|||||||
public class MonteCarloUCTTest {
|
public class MonteCarloUCTTest {
|
||||||
@Test
|
@Test
|
||||||
public void testGenmoveAsW() {
|
public void testGenmoveAsW() {
|
||||||
Policy treeSearch = new MonteCarloUCT(new RandomMovePolicy(),2000L);
|
Policy treeSearch = new MonteCarloUCT(new RandomMovePolicy(),10000L);
|
||||||
GameState gameState = new GameState(6);
|
GameState gameState = new GameState(6);
|
||||||
gameState.playStone(Player.WHITE, Action.getInstance("A2"));
|
gameState.playStone(Player.WHITE, Action.getInstance("A2"));
|
||||||
gameState.playStone(Player.WHITE, Action.getInstance("B1"));
|
gameState.playStone(Player.WHITE, Action.getInstance("B1"));
|
||||||
@@ -35,7 +35,7 @@ public class MonteCarloUCTTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenmoveAsB() {
|
public void testGenmoveAsB() {
|
||||||
Policy treeSearch = new MonteCarloUCT(new RandomMovePolicy(),2000L);
|
Policy treeSearch = new MonteCarloUCT(new RandomMovePolicy(),10000L);
|
||||||
GameState gameState = new GameState(6);
|
GameState gameState = new GameState(6);
|
||||||
gameState.playStone(Player.BLACK, Action.getInstance("A2"));
|
gameState.playStone(Player.BLACK, Action.getInstance("A2"));
|
||||||
gameState.playStone(Player.BLACK, Action.getInstance("B1"));
|
gameState.playStone(Player.BLACK, Action.getInstance("B1"));
|
||||||
|
|||||||
Reference in New Issue
Block a user