Fixed invalid move by Monte Carlo UCT. Still does not handle player's PASS.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user