Fixed use of Zobrist hash for positional superko detection.

This commit is contained in:
cs6601
2012-09-04 16:02:49 -04:00
parent 0bbcb1054d
commit d4acc5beda
14 changed files with 507 additions and 152 deletions

View File

@@ -1,6 +1,8 @@
package net.woodyfolsom.msproj.policy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
@@ -34,22 +36,15 @@ public class RandomTest {
gameState.playStone(Player.BLACK, Action.getInstance("A3"));
gameState.playStone(Player.BLACK, Action.getInstance("A4"));
gameState.playStone(Player.BLACK, Action.getInstance("B1"));;
gameState.playStone(Player.BLACK, Action.getInstance("B2"));
//gameState.playStone('B', 3, GameBoard.BLACK_STONE);
gameState.playStone(Player.BLACK, Action.getInstance("B4"));
gameState.playStone(Player.BLACK, Action.getInstance("B2"));
gameState.playStone(Player.BLACK, Action.getInstance("B4"));
gameState.playStone(Player.BLACK, Action.getInstance("C2"));
gameState.playStone(Player.BLACK, Action.getInstance("C3"));
gameState.playStone(Player.BLACK, Action.getInstance("C4"));
gameState.playStone(Player.BLACK, Action.getInstance("C4"));
gameState.playStone(Player.BLACK, Action.getInstance("D4"));
gameState.playStone(Player.WHITE, Action.getInstance("C1"));
gameState.playStone(Player.WHITE, Action.getInstance("D2"));
gameState.playStone(Player.WHITE, Action.getInstance("D3"));
System.out.println("State before random WHITE move selection:");
System.out.println(gameState);
//This is correct - checked vs. MFOG
@@ -61,4 +56,55 @@ public class RandomTest {
System.out.println(gameState);
}
@Test
public void testIllegalMoveSuicide() {
GameState gameState = new GameState(3);
gameState.playStone(Player.WHITE, Action.getInstance("A1"));
gameState.playStone(Player.WHITE, Action.getInstance("B1"));
gameState.playStone(Player.WHITE, Action.getInstance("B2"));
gameState.playStone(Player.WHITE, Action.getInstance("A3"));
gameState.playStone(Player.WHITE, Action.getInstance("B3"));
System.out.println("State before move: ");
System.out.println(gameState);
RandomMovePolicy randomMovePolicy = new RandomMovePolicy();
//There is only a minute chance (5E-7) that RandomMoveGenerator fails to return an invalid move with probability 1/4
//after 50 calls, if this bug recurs.
for (int i = 0; i < 50; i++) {
Action action = randomMovePolicy.getAction(new GameConfig(),gameState,Player.BLACK);
//System.out.println(action);
assertFalse("RandomMovePolicy returned illegal suicide move A2",action.equals(Action.getInstance("A2")));
}
}
@Test
public void testIllegalMoveKo() {
GameState gameState = new GameState(4);
gameState.playStone(Player.WHITE, Action.getInstance("B1"));
gameState.playStone(Player.WHITE, Action.getInstance("A2"));
gameState.playStone(Player.WHITE, Action.getInstance("C2"));
gameState.playStone(Player.WHITE, Action.getInstance("B3"));
gameState.playStone(Player.BLACK, Action.getInstance("A3"));
gameState.playStone(Player.BLACK, Action.getInstance("C3"));
gameState.playStone(Player.BLACK, Action.getInstance("B4"));
System.out.println("State before move: ");
System.out.println(gameState);
assertTrue(gameState.playStone(Player.BLACK, Action.getInstance("B2")));
System.out.println("State after move: ");
System.out.println(gameState);
RandomMovePolicy randomMovePolicy = new RandomMovePolicy();
//Test that after 50 moves, the policy never returns B3, which would be a Ko violation
for (int i = 0; i < 50; i++) {
Action action = randomMovePolicy.getAction(new GameConfig(),gameState,Player.WHITE);
//System.out.println(action);
assertFalse(action.equals(Action.NONE));
assertFalse("RandomMovePolicy returned Ko violation move B3",action.equals(Action.getInstance("B3")));
}
}
}