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:
@@ -4,27 +4,21 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import net.woodyfolsom.msproj.GameBoard;
|
||||
import net.woodyfolsom.msproj.GameConfig;
|
||||
import net.woodyfolsom.msproj.GameScore;
|
||||
import net.woodyfolsom.msproj.GameState;
|
||||
import net.woodyfolsom.msproj.StateEvaluator;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CaptureTest {
|
||||
@Test
|
||||
public void testCapture() {
|
||||
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);
|
||||
assertTrue(gameState.playStone('B', 2, GameBoard.WHITE_STONE));
|
||||
gameState.playStone(Player.BLACK, Action.getInstance("A2"));
|
||||
gameState.playStone(Player.BLACK, Action.getInstance("B3"));
|
||||
gameState.playStone(Player.BLACK, Action.getInstance("B1"));
|
||||
assertTrue(gameState.playStone(Player.WHITE, Action.getInstance("B2")));
|
||||
|
||||
assertEquals(0,gameState.getBlackPrisoners());
|
||||
assertEquals(0,gameState.getWhitePrisoners());
|
||||
|
||||
assertTrue(gameState.playStone('C', 2, GameBoard.BLACK_STONE));
|
||||
assertTrue(gameState.playStone(Player.BLACK, Action.getInstance("C2")));
|
||||
|
||||
assertEquals(1,gameState.getBlackPrisoners());
|
||||
assertEquals(0,gameState.getWhitePrisoners());
|
||||
@@ -37,25 +31,25 @@ public class CaptureTest {
|
||||
GameConfig gameConfig = new GameConfig();
|
||||
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', 4, GameBoard.BLACK_STONE);
|
||||
gameState.playStone('D', 3, GameBoard.BLACK_STONE);
|
||||
gameState.playStone(Player.BLACK, Action.getInstance("A2"));
|
||||
gameState.playStone(Player.BLACK, Action.getInstance("B3"));
|
||||
gameState.playStone(Player.BLACK, Action.getInstance("B1"));
|
||||
gameState.playStone(Player.BLACK, Action.getInstance("C4"));
|
||||
gameState.playStone(Player.BLACK, Action.getInstance("D3"));
|
||||
|
||||
assertTrue(gameState.playStone('B', 2, GameBoard.WHITE_STONE));
|
||||
assertTrue(gameState.playStone('C', 3, GameBoard.WHITE_STONE));
|
||||
assertTrue(gameState.playStone(Player.WHITE, Action.getInstance("B2")));
|
||||
assertTrue(gameState.playStone(Player.WHITE, Action.getInstance("C3")));
|
||||
|
||||
assertEquals(0,gameState.getBlackPrisoners());
|
||||
assertEquals(0,gameState.getWhitePrisoners());
|
||||
|
||||
assertTrue(gameState.playStone('C', 2, GameBoard.BLACK_STONE));
|
||||
assertTrue(gameState.playStone(Player.BLACK, Action.getInstance("C2")));
|
||||
|
||||
assertEquals(2,gameState.getBlackPrisoners());
|
||||
assertEquals(0,gameState.getWhitePrisoners());
|
||||
|
||||
assertFalse(gameState.playStone('B', 2, GameBoard.WHITE_STONE));
|
||||
assertFalse(gameState.playStone('C', 3, GameBoard.WHITE_STONE));
|
||||
assertFalse(gameState.playStone(Player.WHITE, Action.getInstance("B2")));
|
||||
assertFalse(gameState.playStone(Player.WHITE, Action.getInstance("C3")));
|
||||
|
||||
System.out.println(gameState);
|
||||
|
||||
@@ -67,20 +61,21 @@ public class CaptureTest {
|
||||
public void testCaptureFromEye() {
|
||||
GameState gameState = new GameState(5);
|
||||
|
||||
gameState.playStone('A', 1, GameBoard.BLACK_STONE);
|
||||
gameState.playStone('B', 2, GameBoard.BLACK_STONE);
|
||||
gameState.playStone('C', 1, GameBoard.BLACK_STONE);
|
||||
gameState.playStone('A', 2, GameBoard.WHITE_STONE);
|
||||
gameState.playStone('B', 3, GameBoard.WHITE_STONE);
|
||||
gameState.playStone('C', 2, GameBoard.WHITE_STONE);
|
||||
gameState.playStone(Player.BLACK, Action.getInstance("A1"));
|
||||
gameState.playStone(Player.BLACK, Action.getInstance("B2"));
|
||||
gameState.playStone(Player.BLACK, Action.getInstance("C1"));
|
||||
gameState.playStone(Player.WHITE, Action.getInstance("A2"));
|
||||
gameState.playStone(Player.WHITE, Action.getInstance("B3"));
|
||||
gameState.playStone(Player.WHITE, Action.getInstance("C2"));
|
||||
|
||||
//This capture should be allowed.
|
||||
assertTrue("Capture from within single eye should have been allowed but move was rejected.",
|
||||
gameState.playStone('B', 1, GameBoard.WHITE_STONE));
|
||||
|
||||
assertEquals(0,gameState.getBlackPrisoners());
|
||||
assertEquals(2,gameState.getWhitePrisoners());
|
||||
|
||||
System.out.println("State before WHITE move: ");
|
||||
System.out.println(gameState);
|
||||
|
||||
assertTrue("Capture from within single eye should have been allowed but move was rejected.",
|
||||
gameState.playStone(Player.WHITE, Action.getInstance("B1")));
|
||||
|
||||
assertEquals("BLACK should have 0 prisoners.",0,gameState.getBlackPrisoners());
|
||||
assertEquals("WHITE should have 2 prisoners.",2,gameState.getWhitePrisoners());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user