Files
cs6601p1/test/net/woodyfolsom/msproj/IllegalMoveTest.java
cs6601 2e40440838 Refactoring in progress.
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.
2012-08-30 08:41:03 -04:00

66 lines
2.5 KiB
Java

package net.woodyfolsom.msproj;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class IllegalMoveTest {
@Test
public void testIllegalMoveOnOwnStone() {
GameState gameState = new GameState(5);
gameState.playStone(Player.BLACK, Action.getInstance("B3"));
assertFalse(gameState.playStone(Player.BLACK, Action.getInstance("B3")));
}
@Test
public void testIllegalMoveOnOtherStone() {
GameState gameState = new GameState(5);
gameState.playStone(Player.BLACK, Action.getInstance("B3"));
assertFalse(gameState.playStone(Player.WHITE, Action.getInstance("B3")));
}
@Test
public void testIllegalMoveNoLiberties() {
GameState gameState = new GameState(5);
gameState.playStone(Player.BLACK, Action.getInstance("A2"));
gameState.playStone(Player.BLACK, Action.getInstance("B1"));
gameState.playStone(Player.BLACK, Action.getInstance("B3"));
gameState.playStone(Player.BLACK, Action.getInstance("C2"));
System.out.println(gameState);
assertFalse(gameState.playStone(Player.WHITE, Action.getInstance("B2")));
System.out.println(gameState);
}
@Test
public void testIllegalMoveFormsTrappedGroup() {
GameState gameState = new GameState(9);
gameState.playStone(Player.BLACK, Action.getInstance("A5"));
gameState.playStone(Player.BLACK, Action.getInstance("B6"));
gameState.playStone(Player.BLACK, Action.getInstance("B7"));
gameState.playStone(Player.BLACK, Action.getInstance("A8"));
assertTrue(gameState.playStone(Player.WHITE, Action.getInstance("A6")));
assertFalse(gameState.playStone(Player.WHITE, Action.getInstance("A7")));
System.out.println(gameState);
}
@Test
public void testIllegalMoveFormsTrappedGroup2() {
GameState gameState = new GameState(9);
gameState.playStone(Player.BLACK, Action.getInstance("G1"));
gameState.playStone(Player.BLACK, Action.getInstance("H2"));
gameState.playStone(Player.BLACK, Action.getInstance("H3"));
gameState.playStone(Player.BLACK, Action.getInstance("J4"));
gameState.playStone(Player.BLACK, Action.getInstance("A8"));
assertTrue(gameState.playStone(Player.WHITE, Action.getInstance("H1")));
assertTrue(gameState.playStone(Player.WHITE, Action.getInstance("J2")));
assertTrue(gameState.playStone(Player.WHITE, Action.getInstance("J3")));
System.out.println("State before move: ");
System.out.println(gameState);
assertFalse("Play by WHITE at J1 should have failed.",gameState.playStone(Player.WHITE, Action.getInstance("J1")));
}
}