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