MonteCarloUCT now plays most of a 9x9 game.

Sometimes attempts invalid move (suicide).
See screenshots under bugreports.
This commit is contained in:
cs6601
2012-09-01 18:14:12 -04:00
parent d3c03f2c51
commit 0bbcb1054d
5 changed files with 11 additions and 5 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 404 KiB

View File

@@ -47,7 +47,7 @@ public class GoGame {
} else if ("alphabeta".equals(policyName)) {
return new AlphaBeta();
} else if ("montecarlo".equals(policyName)) {
return new MonteCarloUCT(new RandomMovePolicy(), 2000L);
return new MonteCarloUCT(new RandomMovePolicy(), 10000L);
} else {
LOGGER.info("Unable to create Policy for unsupported name: " + policyName);
System.exit(INVALID_MOVE_GENERATOR);

View File

@@ -13,7 +13,7 @@ import net.woodyfolsom.msproj.tree.GameTreeNode;
import net.woodyfolsom.msproj.tree.MonteCarloProperties;
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 Policy movePolicy;

View File

@@ -82,7 +82,11 @@ public class MonteCarloUCT extends MonteCarlo {
}
nextGameState.playStone(player, action);
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;
}
@@ -108,6 +112,8 @@ public class MonteCarloUCT extends MonteCarlo {
}
} while (action != Action.NONE && rolloutDepth < ROLLOUT_DEPTH_LIMIT);
numStateEvaluations++;
if (stateEvaluator.scoreGame(finalGameState).isWinner(player)) {
return 1;
} else {

View File

@@ -13,7 +13,7 @@ import org.junit.Test;
public class MonteCarloUCTTest {
@Test
public void testGenmoveAsW() {
Policy treeSearch = new MonteCarloUCT(new RandomMovePolicy(),2000L);
Policy treeSearch = new MonteCarloUCT(new RandomMovePolicy(),10000L);
GameState gameState = new GameState(6);
gameState.playStone(Player.WHITE, Action.getInstance("A2"));
gameState.playStone(Player.WHITE, Action.getInstance("B1"));
@@ -35,7 +35,7 @@ public class MonteCarloUCTTest {
@Test
public void testGenmoveAsB() {
Policy treeSearch = new MonteCarloUCT(new RandomMovePolicy(),2000L);
Policy treeSearch = new MonteCarloUCT(new RandomMovePolicy(),10000L);
GameState gameState = new GameState(6);
gameState.playStone(Player.BLACK, Action.getInstance("A2"));
gameState.playStone(Player.BLACK, Action.getInstance("B1"));