Refactoring in progress.

Player and Action classes are now singletons (factory pattern) rather than String values.
Implementing more general treesearch code for minimax, alpha-beta, monte carlo using simplified backup logic.
This commit is contained in:
cs6601
2012-08-30 08:41:03 -04:00
parent b44b666663
commit 2e40440838
26 changed files with 647 additions and 433 deletions

View File

@@ -3,9 +3,6 @@ package net.woodyfolsom.msproj;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import net.woodyfolsom.msproj.GameBoard;
import net.woodyfolsom.msproj.GameState;
import org.junit.Test;
public class IllegalMoveTest {
@@ -13,53 +10,57 @@ public class IllegalMoveTest {
@Test
public void testIllegalMoveOnOwnStone() {
GameState gameState = new GameState(5);
gameState.playStone('B', 3, GameBoard.BLACK_STONE);
assertFalse(gameState.playStone('B', 3, GameBoard.BLACK_STONE));
gameState.playStone(Player.BLACK, Action.getInstance("B3"));
assertFalse(gameState.playStone(Player.BLACK, Action.getInstance("B3")));
}
@Test
public void testIllegalMoveOnOtherStone() {
GameState gameState = new GameState(5);
gameState.playStone('B', 3, GameBoard.BLACK_STONE);
assertFalse(gameState.playStone('B', 3, GameBoard.WHITE_STONE));
gameState.playStone(Player.BLACK, Action.getInstance("B3"));
assertFalse(gameState.playStone(Player.WHITE, Action.getInstance("B3")));
}
@Test
public void testIllegalMoveNoLiberties() {
GameState gameState = new GameState(5);
gameState.playStone('A', 2, GameBoard.BLACK_STONE);
gameState.playStone('B', 3, GameBoard.BLACK_STONE);
gameState.playStone('B', 1, GameBoard.BLACK_STONE);
gameState.playStone('C', 2, GameBoard.BLACK_STONE);
assertFalse(gameState.playStone('B', 2, GameBoard.WHITE_STONE));
gameState.playStone(Player.BLACK, Action.getInstance("A2"));
gameState.playStone(Player.BLACK, Action.getInstance("B1"));
gameState.playStone(Player.BLACK, Action.getInstance("B3"));
gameState.playStone(Player.BLACK, Action.getInstance("C2"));
System.out.println(gameState);
assertFalse(gameState.playStone(Player.WHITE, Action.getInstance("B2")));
System.out.println(gameState);
}
@Test
public void testIllegalMoveFormsTrappedGroup() {
GameState gameState = new GameState(9);
gameState.playStone('A', 5, GameBoard.BLACK_STONE);
gameState.playStone('B', 6, GameBoard.BLACK_STONE);
gameState.playStone('B', 7, GameBoard.BLACK_STONE);
gameState.playStone('A', 8, GameBoard.BLACK_STONE);
assertTrue(gameState.playStone('A', 6, GameBoard.WHITE_STONE));
assertFalse(gameState.playStone('A', 7, GameBoard.WHITE_STONE));
gameState.playStone(Player.BLACK, Action.getInstance("A5"));
gameState.playStone(Player.BLACK, Action.getInstance("B6"));
gameState.playStone(Player.BLACK, Action.getInstance("B7"));
gameState.playStone(Player.BLACK, Action.getInstance("A8"));
assertTrue(gameState.playStone(Player.WHITE, Action.getInstance("A6")));
assertFalse(gameState.playStone(Player.WHITE, Action.getInstance("A7")));
System.out.println(gameState);
}
@Test
public void testIllegalMoveFormsTrappedGroup2() {
GameState gameState = new GameState(9);
gameState.playStone('G', 1, GameBoard.BLACK_STONE);
gameState.playStone('H', 2, GameBoard.BLACK_STONE);
gameState.playStone('H', 3, GameBoard.BLACK_STONE);
gameState.playStone('J', 4, GameBoard.BLACK_STONE);
gameState.playStone('A', 8, GameBoard.BLACK_STONE);
assertTrue(gameState.playStone('H', 1, GameBoard.WHITE_STONE));
assertTrue(gameState.playStone('J', 2, GameBoard.WHITE_STONE));
assertTrue(gameState.playStone('J', 3, GameBoard.WHITE_STONE));
System.out.println(gameState);
assertFalse(gameState.playStone('J', 1, GameBoard.WHITE_STONE));
gameState.playStone(Player.BLACK, Action.getInstance("G1"));
gameState.playStone(Player.BLACK, Action.getInstance("H2"));
gameState.playStone(Player.BLACK, Action.getInstance("H3"));
gameState.playStone(Player.BLACK, Action.getInstance("J4"));
gameState.playStone(Player.BLACK, Action.getInstance("A8"));
assertTrue(gameState.playStone(Player.WHITE, Action.getInstance("H1")));
assertTrue(gameState.playStone(Player.WHITE, Action.getInstance("J2")));
assertTrue(gameState.playStone(Player.WHITE, Action.getInstance("J3")));
System.out.println("State before move: ");
System.out.println(gameState);
assertFalse("Play by WHITE at J1 should have failed.",gameState.playStone(Player.WHITE, Action.getInstance("J1")));
}
}