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.
51 lines
1.4 KiB
Java
51 lines
1.4 KiB
Java
package net.woodyfolsom.msproj.policy;
|
|
|
|
import static org.junit.Assert.assertFalse;
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
import java.util.List;
|
|
|
|
import net.woodyfolsom.msproj.Action;
|
|
import net.woodyfolsom.msproj.GameConfig;
|
|
import net.woodyfolsom.msproj.GameState;
|
|
import net.woodyfolsom.msproj.Player;
|
|
|
|
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(Player.WHITE, Action.getInstance("A2"));
|
|
gameState.playStone(Player.WHITE, Action.getInstance("B1"));
|
|
gameState.playStone(Player.WHITE, Action.getInstance("B4"));
|
|
gameState.playStone(Player.WHITE, Action.getInstance("C2"));
|
|
|
|
assertFalse(gameState.playStone(Player.BLACK, Action.getInstance("A1")));
|
|
|
|
List<Action> validMoves = new ValidMoveGenerator().getActions(new GameConfig(), gameState, Player.BLACK,0);
|
|
|
|
assertTrue(validMoves.size() > 0);
|
|
|
|
for (Action vm : validMoves) {
|
|
System.out.println(vm);
|
|
}
|
|
|
|
assertFalse(validMoves.contains(Action.getInstance("A1")));
|
|
|
|
System.out.println(gameState);
|
|
}
|
|
|
|
}
|