package net.woodyfolsom.msproj;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import net.woodyfolsom.msproj.GameBoard;
import net.woodyfolsom.msproj.GameConfig;
import net.woodyfolsom.msproj.GameScore;
import net.woodyfolsom.msproj.GameState;
import net.woodyfolsom.msproj.StateEvaluator;

import org.junit.Test;

public class CaptureTest {
	@Test
	public void testCapture() {
		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);
		assertTrue(gameState.playStone('B', 2, GameBoard.WHITE_STONE));
		
		assertEquals(0,gameState.getBlackPrisoners());
		assertEquals(0,gameState.getWhitePrisoners());
		
		assertTrue(gameState.playStone('C', 2, GameBoard.BLACK_STONE));
		
		assertEquals(1,gameState.getBlackPrisoners());
		assertEquals(0,gameState.getWhitePrisoners());
		
		System.out.println(gameState);
	}
	
	@Test
	public void testMultiGroupCapture() {
		GameConfig gameConfig = new GameConfig();
		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', 4, GameBoard.BLACK_STONE);
		gameState.playStone('D', 3, GameBoard.BLACK_STONE);
		
		assertTrue(gameState.playStone('B', 2, GameBoard.WHITE_STONE));
		assertTrue(gameState.playStone('C', 3, GameBoard.WHITE_STONE));
		
		assertEquals(0,gameState.getBlackPrisoners());
		assertEquals(0,gameState.getWhitePrisoners());
		
		assertTrue(gameState.playStone('C', 2, GameBoard.BLACK_STONE));
		
		assertEquals(2,gameState.getBlackPrisoners());
		assertEquals(0,gameState.getWhitePrisoners());
		
		assertFalse(gameState.playStone('B', 2, GameBoard.WHITE_STONE));
		assertFalse(gameState.playStone('C', 3, GameBoard.WHITE_STONE));
		
		System.out.println(gameState);
		
		GameScore gameScore = new StateEvaluator(gameConfig).scoreGame(gameState);
		System.out.println(gameScore.getScoreReport());
	}
	
	@Test
	public void testCaptureFromEye() {
		GameState gameState = new GameState(5);
		
		gameState.playStone('A', 1, GameBoard.BLACK_STONE);
		gameState.playStone('B', 2, GameBoard.BLACK_STONE);
		gameState.playStone('C', 1, GameBoard.BLACK_STONE);
		gameState.playStone('A', 2, GameBoard.WHITE_STONE);
		gameState.playStone('B', 3, GameBoard.WHITE_STONE);
		gameState.playStone('C', 2, GameBoard.WHITE_STONE);
		
		//This capture should be allowed.
		assertTrue("Capture from within single eye should have been allowed but move was rejected.",
				gameState.playStone('B', 1, GameBoard.WHITE_STONE));

		assertEquals(0,gameState.getBlackPrisoners());
		assertEquals(2,gameState.getWhitePrisoners());
		
		System.out.println(gameState);
	}
}
