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

@@ -1,12 +1,10 @@
package net.woodyfolsom.msproj.policy;
import static org.junit.Assert.assertEquals;
import net.woodyfolsom.msproj.GameBoard;
import net.woodyfolsom.msproj.Action;
import net.woodyfolsom.msproj.GameConfig;
import net.woodyfolsom.msproj.GameState;
import net.woodyfolsom.msproj.policy.AlphaBeta;
import net.woodyfolsom.msproj.policy.Policy;
import net.woodyfolsom.msproj.Player;
import org.junit.Test;
@@ -15,43 +13,40 @@ public class AlphaBetaTest {
public void testGenmoveAsW() {
Policy treeSearch = new AlphaBeta();
GameState gameState = new GameState(6);
gameState.playStone('A', 2, GameBoard.WHITE_STONE);
gameState.playStone('B', 1, GameBoard.WHITE_STONE);
gameState.playStone('C', 2, GameBoard.WHITE_STONE);
gameState.playStone('B', 2, GameBoard.BLACK_STONE);
gameState.playStone(Player.WHITE, Action.getInstance("A2"));
gameState.playStone(Player.WHITE, Action.getInstance("B1"));
gameState.playStone(Player.WHITE, Action.getInstance("C2"));
gameState.playStone(Player.BLACK, Action.getInstance("B2"));
String move = treeSearch.getAction(new GameConfig(), gameState, "b");
Action move = treeSearch.getAction(new GameConfig(), gameState, Player.WHITE);
System.out.println(gameState);
System.out.println("Generated move: " + move);
assertEquals("Expected B3 but was: " + move, "B3", move);
gameState.playStone("b", move);
assertEquals("Expected B3 but was: " + move, Action.getInstance("B3"), move);
gameState.playStone(Player.WHITE, move);
System.out.println("Final board state:");
System.out.println(gameState);
assertEquals(Policy.PASS,
treeSearch.getAction(new GameConfig(), gameState, "?"));
}
@Test
public void testGenmoveAsB() {
Policy treeSearch = new AlphaBeta();
GameState gameState = new GameState(6);
gameState.playStone('A', 2, GameBoard.BLACK_STONE);
gameState.playStone('B', 1, GameBoard.BLACK_STONE);
gameState.playStone('C', 2, GameBoard.BLACK_STONE);
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("C2"));
gameState.playStone(Player.WHITE, Action.getInstance("B2"));
String move = treeSearch.getAction(new GameConfig(), gameState, "b");
Action move = treeSearch.getAction(new GameConfig(), gameState, Player.BLACK);
System.out.println(gameState);
System.out.println("Generated move: " + move);
assertEquals("Expected B3 but was: " + move, "B3", move);
gameState.playStone("b", move);
assertEquals("Expected B3 but was: " + move, Action.getInstance("B3"), move);
gameState.playStone(Player.BLACK, move);
System.out.println("Final board state:");
System.out.println(gameState);
assertEquals(Policy.PASS,
treeSearch.getAction(new GameConfig(), gameState, "?"));
}
}