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"))); } }