Fixed invalid move by Monte Carlo UCT. Still does not handle player's PASS.

This commit is contained in:
2012-09-24 11:08:03 -04:00
parent ded284deb4
commit 8d466d90fe
20 changed files with 4368 additions and 1380 deletions

View File

@@ -1,5 +1,6 @@
package net.woodyfolsom.msproj;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
@@ -9,8 +10,14 @@ public class LegalMoveTest {
public void testLegalMove1Liberty() {
GameState gameState = new GameState(5);
gameState.playStone(Player.BLACK, Action.getInstance("A2"));
assertEquals(Player.WHITE, gameState.getPlayerToMove());
gameState.playStone(Player.WHITE, Action.PASS);
gameState.playStone(Player.BLACK, Action.getInstance("B3"));
gameState.playStone(Player.WHITE, Action.PASS);
gameState.playStone(Player.BLACK, Action.getInstance("B1"));
assertTrue(gameState.playStone(Player.WHITE, Action.getInstance("B2")));
System.out.println(gameState);
}

View File

@@ -1,6 +1,7 @@
package net.woodyfolsom.msproj.policy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import net.woodyfolsom.msproj.Action;
import net.woodyfolsom.msproj.GameConfig;
@@ -54,4 +55,25 @@ public class MonteCarloUCTTest {
System.out.println(gameState);
}
@Test
public void testIllegalMoveRejection() {
Policy treeSearch = new MonteCarloUCT(new RandomMovePolicy(),2000L);
GameState gameState = new GameState(4);
gameState.playStone(Player.WHITE, Action.getInstance("A2"));
gameState.playStone(Player.WHITE, Action.getInstance("B1"));
gameState.playStone(Player.WHITE, Action.getInstance("C2"));
gameState.playStone(Player.WHITE, Action.getInstance("B3"));
Action move;
for (int i = 0; i < 10; i++) {
move = treeSearch.getAction(new GameConfig(), gameState, Player.BLACK);
System.out.println("Generated move: " + move);
GameState stateCopy = new GameState(gameState);
stateCopy.playStone(Player.BLACK, move);
System.out.println(stateCopy);
assertFalse(Action.getInstance("B2").equals(move));
}
}
}