Substantial refactoring to implement correct Naive, UCT Monte Carlo tree search methods.
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.
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
package cs6601.p1;
|
||||
package net.woodyfolsom.msproj;
|
||||
|
||||
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 {
|
||||
@@ -1,7 +1,9 @@
|
||||
package cs6601.p1;
|
||||
package net.woodyfolsom.msproj;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import net.woodyfolsom.msproj.GameScore;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class GameScoreTest {
|
||||
@@ -1,8 +1,11 @@
|
||||
package cs6601.p1;
|
||||
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 {
|
||||
@@ -1,7 +1,10 @@
|
||||
package cs6601.p1;
|
||||
package net.woodyfolsom.msproj;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import net.woodyfolsom.msproj.GameBoard;
|
||||
import net.woodyfolsom.msproj.GameState;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class LegalMoveTest {
|
||||
@@ -1,12 +1,16 @@
|
||||
package cs6601.p1;
|
||||
package net.woodyfolsom.msproj;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
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;
|
||||
|
||||
import cs6601.p1.generator.AlphaBetaMoveGenerator;
|
||||
import cs6601.p1.generator.MoveGenerator;
|
||||
|
||||
public class StateEvaluatorTest {
|
||||
GameConfig gameConfig = new GameConfig();
|
||||
@@ -1,4 +1,8 @@
|
||||
package cs6601.p1;
|
||||
package net.woodyfolsom.msproj;
|
||||
|
||||
import net.woodyfolsom.msproj.GameBoard;
|
||||
import net.woodyfolsom.msproj.GameState;
|
||||
import net.woodyfolsom.msproj.TerritoryMarker;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
17
test/net/woodyfolsom/msproj/ZobristHashGeneratorTest.java
Normal file
17
test/net/woodyfolsom/msproj/ZobristHashGeneratorTest.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package net.woodyfolsom.msproj;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import net.woodyfolsom.msproj.ZobristHashGenerator;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ZobristHashGeneratorTest {
|
||||
|
||||
@Test
|
||||
public void testConstructor5x5() {
|
||||
ZobristHashGenerator zobHashGen = ZobristHashGenerator.getInstance(5);
|
||||
assertNotNull(zobHashGen);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,53 +1,57 @@
|
||||
package cs6601.p1.generator;
|
||||
package net.woodyfolsom.msproj.policy;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
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 cs6601.p1.GameBoard;
|
||||
import cs6601.p1.GameConfig;
|
||||
import cs6601.p1.GameState;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AlphaBetaTest {
|
||||
@Test
|
||||
public void testGenmoveAsW() {
|
||||
MoveGenerator moveGenerator = new AlphaBetaMoveGenerator();
|
||||
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 = moveGenerator.genMove(new GameConfig(), gameState, "b");
|
||||
|
||||
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(MoveGenerator.PASS,moveGenerator.genMove(new GameConfig(), gameState, "?"));
|
||||
|
||||
assertEquals(Policy.PASS,
|
||||
treeSearch.getAction(new GameConfig(), gameState, "?"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGenmoveAsB() {
|
||||
MoveGenerator moveGenerator = new AlphaBetaMoveGenerator();
|
||||
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 = moveGenerator.genMove(new GameConfig(), gameState, "b");
|
||||
|
||||
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(MoveGenerator.PASS,moveGenerator.genMove(new GameConfig(), gameState, "?"));
|
||||
|
||||
assertEquals(Policy.PASS,
|
||||
treeSearch.getAction(new GameConfig(), gameState, "?"));
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,33 @@
|
||||
package cs6601.p1.generator;
|
||||
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.Policy;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import cs6601.p1.GameBoard;
|
||||
import cs6601.p1.GameConfig;
|
||||
import cs6601.p1.GameState;
|
||||
import cs6601.p1.generator.MoveGenerator;
|
||||
|
||||
public class MinimaxTest {
|
||||
|
||||
@Test
|
||||
public void testGenmove() {
|
||||
MoveGenerator moveGenerator = new MinimaxMoveGenerator();
|
||||
Policy moveGenerator = new Minimax();
|
||||
GameState gameState = new GameState(5);
|
||||
gameState.playStone('A', 2, GameBoard.BLACK_STONE);
|
||||
gameState.playStone('B', 1, GameBoard.BLACK_STONE);
|
||||
gameState.playStone('C', 2, GameBoard.BLACK_STONE);
|
||||
gameState.playStone('B', 4, GameBoard.BLACK_STONE);
|
||||
|
||||
String move = moveGenerator.genMove(new GameConfig(), gameState, "w");
|
||||
String move = moveGenerator.getAction(new GameConfig(), gameState, "w");
|
||||
System.out.println("Generated move: " + move);
|
||||
gameState.playStone("w", move);
|
||||
|
||||
System.out.println(gameState);
|
||||
|
||||
assertEquals(MoveGenerator.PASS,moveGenerator.genMove(new GameConfig(), gameState, "?"));
|
||||
assertEquals(Policy.PASS,moveGenerator.getAction(new GameConfig(), gameState, "?"));
|
||||
|
||||
System.out.println(gameState);
|
||||
}
|
||||
@@ -1,27 +1,28 @@
|
||||
package cs6601.p1.generator;
|
||||
package net.woodyfolsom.msproj.policy;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import net.woodyfolsom.msproj.GameBoard;
|
||||
import net.woodyfolsom.msproj.GameConfig;
|
||||
import net.woodyfolsom.msproj.GameState;
|
||||
import net.woodyfolsom.msproj.policy.Policy;
|
||||
import net.woodyfolsom.msproj.policy.RandomMovePolicy;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import cs6601.p1.GameBoard;
|
||||
import cs6601.p1.GameConfig;
|
||||
import cs6601.p1.GameState;
|
||||
import cs6601.p1.generator.MoveGenerator;
|
||||
import cs6601.p1.generator.RandomMoveGenerator;
|
||||
|
||||
public class RandomTest {
|
||||
|
||||
@Test
|
||||
public void testGenmove() {
|
||||
MoveGenerator moveGenerator = new RandomMoveGenerator();
|
||||
Policy moveGenerator = new RandomMovePolicy();
|
||||
GameState gameState = new GameState(5);
|
||||
moveGenerator.genMove(new GameConfig(), gameState, "b");
|
||||
moveGenerator.getAction(new GameConfig(), gameState, "b");
|
||||
gameState = new GameState(5);
|
||||
moveGenerator.genMove(new GameConfig(), gameState, "w");
|
||||
moveGenerator.getAction(new GameConfig(), gameState, "w");
|
||||
|
||||
assertEquals(MoveGenerator.PASS,moveGenerator.genMove(new GameConfig(), gameState, "?"));
|
||||
assertEquals(Policy.PASS,moveGenerator.getAction(new GameConfig(), gameState, "?"));
|
||||
|
||||
System.out.println(gameState);
|
||||
}
|
||||
@@ -46,7 +47,7 @@ public class RandomTest {
|
||||
assertTrue(gameState.playStone('D', 3, GameBoard.WHITE_STONE));
|
||||
System.out.println(gameState);
|
||||
//This is correct - checked vs. MFOG
|
||||
assertEquals("B3", new RandomMoveGenerator().genMove(new GameConfig(), gameState, "w"));
|
||||
assertEquals("B3", new RandomMovePolicy().getAction(new GameConfig(), gameState, "w"));
|
||||
System.out.println(gameState);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
package cs6601.p1.generator;
|
||||
package net.woodyfolsom.msproj.policy;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.woodyfolsom.msproj.GameBoard;
|
||||
import net.woodyfolsom.msproj.GameConfig;
|
||||
import net.woodyfolsom.msproj.GameState;
|
||||
import net.woodyfolsom.msproj.policy.ValidMoveGenerator;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import cs6601.p1.GameBoard;
|
||||
import cs6601.p1.GameConfig;
|
||||
import cs6601.p1.GameState;
|
||||
|
||||
public class ValidMoveGeneratorTest {
|
||||
|
||||
@@ -30,7 +32,7 @@ public class ValidMoveGeneratorTest {
|
||||
gameState.playStone('C', 2, GameBoard.WHITE_STONE);
|
||||
assertFalse(gameState.playStone('A', 1, GameBoard.BLACK_STONE));
|
||||
|
||||
List<String> validMoves = new ValidMoveGenerator().genMoves(new GameConfig(), gameState, "b",0);
|
||||
List<String> validMoves = new ValidMoveGenerator().getActions(new GameConfig(), gameState, "b",0);
|
||||
assertTrue(validMoves.size() > 0);
|
||||
for (String vm : validMoves) {
|
||||
System.out.println(vm);
|
||||
Reference in New Issue
Block a user