Files
msproj/test/net/woodyfolsom/msproj/policy/RandomTest.java
cs6601 d3c03f2c51 Updated RandomMoveGenerator to support MonteCarloUCT.
Now possible to prohibit a Collection of Actions from being included in the List of returned actions (or as a single returned value).
All unit tests now pass with the exception of MonteCarloUCT.

TODO: playerToMove and previousPlayerPassed should be made part of the GameState.
This would remove the superfluous Player parameter from many methods and make it possible
to check for the "I'm ahead and my opponent is offering to end the game" killer move.
2012-08-31 09:17:43 -04:00

65 lines
2.3 KiB
Java

package net.woodyfolsom.msproj.policy;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
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 RandomTest {
@Test(expected = IllegalArgumentException.class)
public void testGenmoveForNone() {
Policy moveGenerator = new RandomMovePolicy();
GameState gameState = new GameState(5);
moveGenerator.getAction(new GameConfig(), gameState, Player.BLACK);
gameState = new GameState(5);
moveGenerator.getAction(new GameConfig(), gameState, Player.WHITE);
assertEquals(Action.PASS, moveGenerator.getAction(new GameConfig(), gameState, Player.NONE));
}
@Test
public void testAlternativeToIllegalMove() {
GameState gameState = new GameState(4);
gameState.playStone(Player.BLACK, Action.getInstance("A1"));
gameState.playStone(Player.BLACK, Action.getInstance("A2"));
gameState.playStone(Player.BLACK, Action.getInstance("A3"));
gameState.playStone(Player.BLACK, Action.getInstance("A4"));
gameState.playStone(Player.BLACK, Action.getInstance("B1"));;
gameState.playStone(Player.BLACK, Action.getInstance("B2"));
//gameState.playStone('B', 3, GameBoard.BLACK_STONE);
gameState.playStone(Player.BLACK, Action.getInstance("B4"));
gameState.playStone(Player.BLACK, Action.getInstance("C2"));
gameState.playStone(Player.BLACK, Action.getInstance("C3"));
gameState.playStone(Player.BLACK, Action.getInstance("C4"));
gameState.playStone(Player.BLACK, Action.getInstance("D4"));
gameState.playStone(Player.WHITE, Action.getInstance("C1"));
gameState.playStone(Player.WHITE, Action.getInstance("D2"));
gameState.playStone(Player.WHITE, Action.getInstance("D3"));
System.out.println("State before random WHITE move selection:");
System.out.println(gameState);
//This is correct - checked vs. MFOG
//PASS would otherwise be a valid move
List<Action> prohibitedMoves = new ArrayList<Action>();
prohibitedMoves.add(Action.PASS);
assertEquals(Action.getInstance("B3"), new RandomMovePolicy().getAction(new GameConfig(), gameState, prohibitedMoves, Player.WHITE));
System.out.println(gameState);
}
}