Removed unnecessary distinction between policy and tree search (tree search is a special kind of policy). Calculation of all valid moves / arbitrary sets of moves is now a seperate class, as it serves a different purpose than a policy. Introduced regression error in AlphaBeta test.
57 lines
1.8 KiB
Java
57 lines
1.8 KiB
Java
package net.woodyfolsom.msproj.policy;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import net.woodyfolsom.msproj.GameBoard;
|
|
import net.woodyfolsom.msproj.GameConfig;
|
|
import net.woodyfolsom.msproj.GameState;
|
|
import net.woodyfolsom.msproj.policy.AlphaBeta;
|
|
import net.woodyfolsom.msproj.policy.Policy;
|
|
|
|
import org.junit.Test;
|
|
|
|
public class AlphaBetaTest {
|
|
@Test
|
|
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);
|
|
|
|
String move = treeSearch.getAction(new GameConfig(), gameState, "b");
|
|
System.out.println(gameState);
|
|
|
|
System.out.println("Generated move: " + move);
|
|
assertEquals("Expected B3 but was: " + move, "B3", move);
|
|
gameState.playStone("b", move);
|
|
|
|
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);
|
|
|
|
String move = treeSearch.getAction(new GameConfig(), gameState, "b");
|
|
System.out.println(gameState);
|
|
|
|
System.out.println("Generated move: " + move);
|
|
assertEquals("Expected B3 but was: " + move, "B3", move);
|
|
gameState.playStone("b", move);
|
|
|
|
System.out.println(gameState);
|
|
|
|
assertEquals(Policy.PASS,
|
|
treeSearch.getAction(new GameConfig(), gameState, "?"));
|
|
}
|
|
} |