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:
86
test/net/woodyfolsom/msproj/CaptureTest.java
Normal file
86
test/net/woodyfolsom/msproj/CaptureTest.java
Normal file
@@ -0,0 +1,86 @@
|
||||
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 {
|
||||
@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));
|
||||
|
||||
assertEquals(0,gameState.getBlackPrisoners());
|
||||
assertEquals(0,gameState.getWhitePrisoners());
|
||||
|
||||
assertTrue(gameState.playStone('C', 2, GameBoard.BLACK_STONE));
|
||||
|
||||
assertEquals(1,gameState.getBlackPrisoners());
|
||||
assertEquals(0,gameState.getWhitePrisoners());
|
||||
|
||||
System.out.println(gameState);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiGroupCapture() {
|
||||
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);
|
||||
|
||||
assertTrue(gameState.playStone('B', 2, GameBoard.WHITE_STONE));
|
||||
assertTrue(gameState.playStone('C', 3, GameBoard.WHITE_STONE));
|
||||
|
||||
assertEquals(0,gameState.getBlackPrisoners());
|
||||
assertEquals(0,gameState.getWhitePrisoners());
|
||||
|
||||
assertTrue(gameState.playStone('C', 2, GameBoard.BLACK_STONE));
|
||||
|
||||
assertEquals(2,gameState.getBlackPrisoners());
|
||||
assertEquals(0,gameState.getWhitePrisoners());
|
||||
|
||||
assertFalse(gameState.playStone('B', 2, GameBoard.WHITE_STONE));
|
||||
assertFalse(gameState.playStone('C', 3, GameBoard.WHITE_STONE));
|
||||
|
||||
System.out.println(gameState);
|
||||
|
||||
GameScore gameScore = new StateEvaluator(gameConfig).scoreGame(gameState);
|
||||
System.out.println(gameScore.getScoreReport());
|
||||
}
|
||||
|
||||
@Test
|
||||
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);
|
||||
|
||||
//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(gameState);
|
||||
}
|
||||
}
|
||||
28
test/net/woodyfolsom/msproj/GameScoreTest.java
Normal file
28
test/net/woodyfolsom/msproj/GameScoreTest.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package net.woodyfolsom.msproj;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import net.woodyfolsom.msproj.GameScore;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class GameScoreTest {
|
||||
|
||||
@Test
|
||||
public void testGetAggregateScoreZero() {
|
||||
GameScore gameScore = new GameScore(0,0,0);
|
||||
assertEquals(GameScore.NORMALIZED_ZERO_SCORE, gameScore.getAggregateScore());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAggregateScoreBlackWinsNoKomi() {
|
||||
GameScore gameScore = new GameScore(25,2,0);
|
||||
assertEquals(425, gameScore.getAggregateScore());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAggregateScoreWhiteWinsWithKomi() {
|
||||
GameScore gameScore = new GameScore(10,12,6.5);
|
||||
assertEquals(362, gameScore.getAggregateScore());
|
||||
}
|
||||
}
|
||||
65
test/net/woodyfolsom/msproj/IllegalMoveTest.java
Normal file
65
test/net/woodyfolsom/msproj/IllegalMoveTest.java
Normal file
@@ -0,0 +1,65 @@
|
||||
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 {
|
||||
|
||||
@Test
|
||||
public void testIllegalMoveOnOwnStone() {
|
||||
GameState gameState = new GameState(5);
|
||||
gameState.playStone('B', 3, GameBoard.BLACK_STONE);
|
||||
assertFalse(gameState.playStone('B', 3, GameBoard.BLACK_STONE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIllegalMoveOnOtherStone() {
|
||||
GameState gameState = new GameState(5);
|
||||
gameState.playStone('B', 3, GameBoard.BLACK_STONE);
|
||||
assertFalse(gameState.playStone('B', 3, GameBoard.WHITE_STONE));
|
||||
}
|
||||
|
||||
@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));
|
||||
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));
|
||||
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));
|
||||
System.out.println(gameState);
|
||||
}
|
||||
}
|
||||
20
test/net/woodyfolsom/msproj/LegalMoveTest.java
Normal file
20
test/net/woodyfolsom/msproj/LegalMoveTest.java
Normal file
@@ -0,0 +1,20 @@
|
||||
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 {
|
||||
@Test
|
||||
public void testLegalMove1Liberty() {
|
||||
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));
|
||||
System.out.println(gameState);
|
||||
}
|
||||
}
|
||||
100
test/net/woodyfolsom/msproj/StateEvaluatorTest.java
Normal file
100
test/net/woodyfolsom/msproj/StateEvaluatorTest.java
Normal file
@@ -0,0 +1,100 @@
|
||||
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;
|
||||
|
||||
|
||||
public class StateEvaluatorTest {
|
||||
GameConfig gameConfig = new GameConfig();
|
||||
|
||||
@Test
|
||||
public void testScoreEmptyBoard() {
|
||||
GameState gameState = new GameState(5);
|
||||
GameScore gameScore = new StateEvaluator(gameConfig).scoreGame(gameState);
|
||||
|
||||
assertEquals(0.0,gameScore.getWhiteScore(),0.5);
|
||||
assertEquals(0.0,gameScore.getBlackScore(),0.5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScoreFirstMove() {
|
||||
GameState gameState = new GameState(5);
|
||||
gameState.playStone('B',3,GameBoard.BLACK_STONE);
|
||||
|
||||
GameScore gameScore = new StateEvaluator(gameConfig).scoreGame(gameState);
|
||||
|
||||
System.out.println(gameScore.getScoreReport());
|
||||
|
||||
assertEquals(0.0,gameScore.getWhiteScore(),0.5);
|
||||
assertEquals(25.0,gameScore.getBlackScore(),0.5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScoreTiedAtMove2() {
|
||||
GameState gameState = new GameState(5);
|
||||
|
||||
gameState.playStone('B',3,GameBoard.BLACK_STONE);
|
||||
gameState.playStone('A',1,GameBoard.WHITE_STONE);
|
||||
GameScore gameScore = new StateEvaluator(gameConfig).scoreGame(gameState);
|
||||
|
||||
System.out.println(gameScore.getScoreReport());
|
||||
|
||||
assertEquals(1.0,gameScore.getWhiteScore(),0.5);
|
||||
assertEquals(1.0,gameScore.getBlackScore(),0.5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScoreTerritory() {
|
||||
GameState gameState = new GameState(5);
|
||||
|
||||
gameState.playStone('A',2,GameBoard.BLACK_STONE);
|
||||
gameState.playStone('B',3,GameBoard.BLACK_STONE);
|
||||
gameState.playStone('C',2,GameBoard.BLACK_STONE);
|
||||
gameState.playStone('B',1,GameBoard.BLACK_STONE);
|
||||
gameState.playStone('E',5,GameBoard.WHITE_STONE);
|
||||
|
||||
System.out.println(gameState);
|
||||
GameScore gameScore = new StateEvaluator(gameConfig).scoreGame(gameState);
|
||||
|
||||
System.out.println(gameScore.getScoreReport());
|
||||
|
||||
assertEquals(1.0,gameScore.getWhiteScore(),0.5);
|
||||
assertEquals(6.0,gameScore.getBlackScore(),0.5);
|
||||
//Black should be up by 5 if Black's territory at A1 & B2 is scored correctly.
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCaptureAggScore() {
|
||||
GameState gameState = new GameState(9);
|
||||
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 moveToA1 = new GameState(gameState);
|
||||
GameState capAtB3 = new GameState(gameState);
|
||||
|
||||
moveToA1.playStone("w","A1");
|
||||
capAtB3.playStone("w", "B3");
|
||||
|
||||
System.out.println(moveToA1);
|
||||
System.out.println(capAtB3);
|
||||
|
||||
StateEvaluator eval = new StateEvaluator(new GameConfig());
|
||||
int scoreA1 = eval.scoreGame(moveToA1).getAggregateScore();
|
||||
int scoreB3 = eval.scoreGame(capAtB3).getAggregateScore();
|
||||
|
||||
System.out.println("Score at A1: " + scoreA1);
|
||||
System.out.println("Score at B3: " + scoreB3);
|
||||
//moving as white, lower is better
|
||||
assertTrue(scoreA1 > scoreB3);
|
||||
}
|
||||
}
|
||||
23
test/net/woodyfolsom/msproj/TerritoryFinderTest.java
Normal file
23
test/net/woodyfolsom/msproj/TerritoryFinderTest.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package net.woodyfolsom.msproj;
|
||||
|
||||
import net.woodyfolsom.msproj.GameBoard;
|
||||
import net.woodyfolsom.msproj.GameState;
|
||||
import net.woodyfolsom.msproj.TerritoryMarker;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TerritoryFinderTest {
|
||||
@Test
|
||||
public void testMarkTerritory() {
|
||||
GameState gameState = new GameState(5);
|
||||
|
||||
gameState.playStone('A',2,GameBoard.BLACK_STONE);
|
||||
gameState.playStone('B',3,GameBoard.BLACK_STONE);
|
||||
gameState.playStone('C',2,GameBoard.BLACK_STONE);
|
||||
gameState.playStone('B',1,GameBoard.BLACK_STONE);
|
||||
gameState.playStone('E',5,GameBoard.WHITE_STONE);
|
||||
|
||||
TerritoryMarker.markTerritory(gameState.getGameBoard());
|
||||
System.out.println(gameState);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
57
test/net/woodyfolsom/msproj/policy/AlphaBetaTest.java
Normal file
57
test/net/woodyfolsom/msproj/policy/AlphaBetaTest.java
Normal file
@@ -0,0 +1,57 @@
|
||||
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, "?"));
|
||||
}
|
||||
}
|
||||
34
test/net/woodyfolsom/msproj/policy/MinimaxTest.java
Normal file
34
test/net/woodyfolsom/msproj/policy/MinimaxTest.java
Normal file
@@ -0,0 +1,34 @@
|
||||
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;
|
||||
|
||||
|
||||
public class MinimaxTest {
|
||||
|
||||
@Test
|
||||
public void testGenmove() {
|
||||
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.getAction(new GameConfig(), gameState, "w");
|
||||
System.out.println("Generated move: " + move);
|
||||
gameState.playStone("w", move);
|
||||
|
||||
System.out.println(gameState);
|
||||
|
||||
assertEquals(Policy.PASS,moveGenerator.getAction(new GameConfig(), gameState, "?"));
|
||||
|
||||
System.out.println(gameState);
|
||||
}
|
||||
}
|
||||
53
test/net/woodyfolsom/msproj/policy/RandomTest.java
Normal file
53
test/net/woodyfolsom/msproj/policy/RandomTest.java
Normal file
@@ -0,0 +1,53 @@
|
||||
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;
|
||||
|
||||
|
||||
public class RandomTest {
|
||||
|
||||
@Test
|
||||
public void testGenmove() {
|
||||
Policy moveGenerator = new RandomMovePolicy();
|
||||
GameState gameState = new GameState(5);
|
||||
moveGenerator.getAction(new GameConfig(), gameState, "b");
|
||||
gameState = new GameState(5);
|
||||
moveGenerator.getAction(new GameConfig(), gameState, "w");
|
||||
|
||||
assertEquals(Policy.PASS,moveGenerator.getAction(new GameConfig(), gameState, "?"));
|
||||
|
||||
System.out.println(gameState);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlternativeToIllegalMove() {
|
||||
GameState gameState = new GameState(4);
|
||||
gameState.playStone('A', 1, GameBoard.BLACK_STONE);
|
||||
gameState.playStone('A', 2, GameBoard.BLACK_STONE);
|
||||
gameState.playStone('A', 3, GameBoard.BLACK_STONE);
|
||||
gameState.playStone('A', 4, GameBoard.BLACK_STONE);
|
||||
gameState.playStone('B', 1, GameBoard.BLACK_STONE);
|
||||
gameState.playStone('B', 2, GameBoard.BLACK_STONE);
|
||||
//gameState.playStone('B', 3, GameBoard.BLACK_STONE);
|
||||
gameState.playStone('B', 4, GameBoard.BLACK_STONE);
|
||||
gameState.playStone('C', 2, GameBoard.BLACK_STONE);
|
||||
gameState.playStone('C', 3, GameBoard.BLACK_STONE);
|
||||
gameState.playStone('C', 4, GameBoard.BLACK_STONE);
|
||||
gameState.playStone('D', 4, GameBoard.BLACK_STONE);
|
||||
assertTrue(gameState.playStone('C', 1, GameBoard.WHITE_STONE));
|
||||
assertTrue(gameState.playStone('D', 2, GameBoard.WHITE_STONE));
|
||||
assertTrue(gameState.playStone('D', 3, GameBoard.WHITE_STONE));
|
||||
System.out.println(gameState);
|
||||
//This is correct - checked vs. MFOG
|
||||
assertEquals("B3", new RandomMovePolicy().getAction(new GameConfig(), gameState, "w"));
|
||||
System.out.println(gameState);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
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;
|
||||
|
||||
|
||||
public class ValidMoveGeneratorTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
/* move generator should not include A1 here when playing as black:
|
||||
A B C D E
|
||||
5 . . . . . 5
|
||||
4 . O . . . 4
|
||||
3 . . . . . 3 WHITE(O) has captured 0 stones
|
||||
2 O . O . . 2 BLACK(X) has captured 0 stones
|
||||
1 . O . . . 1
|
||||
A B C D E
|
||||
*/
|
||||
GameState gameState = new GameState(5);
|
||||
gameState.playStone('A', 2, GameBoard.WHITE_STONE);
|
||||
gameState.playStone('B', 1, GameBoard.WHITE_STONE);
|
||||
gameState.playStone('B', 4, GameBoard.WHITE_STONE);
|
||||
gameState.playStone('C', 2, GameBoard.WHITE_STONE);
|
||||
assertFalse(gameState.playStone('A', 1, GameBoard.BLACK_STONE));
|
||||
|
||||
List<String> validMoves = new ValidMoveGenerator().getActions(new GameConfig(), gameState, "b",0);
|
||||
assertTrue(validMoves.size() > 0);
|
||||
for (String vm : validMoves) {
|
||||
System.out.println(vm);
|
||||
}
|
||||
assertFalse(validMoves.contains("A1"));
|
||||
|
||||
System.out.println(gameState);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user