package net.woodyfolsom.msproj;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class LegalMoveTest {
	@Test
	public void testLegalMove1Liberty() {
		GameState gameState = new GameState(5);
		gameState.playStone(Player.BLACK, Action.getInstance("A2"));
		gameState.playStone(Player.BLACK, Action.getInstance("B3"));
		gameState.playStone(Player.BLACK, Action.getInstance("B1"));
		assertTrue(gameState.playStone(Player.WHITE, Action.getInstance("B2")));
		System.out.println(gameState);
	}
	
	@Test
	public void testLegalMove2Liberties() {
		//Unit test based on illegal move from 9x9 game using MonteCarloUCT
		//Illegal move detected by gokgs.com server
		GameState gameState = new GameState(9);
		gameState.playStone(Player.BLACK, Action.getInstance("G5"));
		gameState.playStone(Player.BLACK, Action.getInstance("G7"));
		gameState.playStone(Player.BLACK, Action.getInstance("F6"));
		gameState.playStone(Player.BLACK, Action.getInstance("H6"));
		gameState.playStone(Player.BLACK, Action.getInstance("C7"));
		gameState.playStone(Player.BLACK, Action.getInstance("D7"));
		gameState.playStone(Player.BLACK, Action.getInstance("E7"));
		gameState.playStone(Player.BLACK, Action.getInstance("F7"));
		gameState.playStone(Player.BLACK, Action.getInstance("G8"));
		gameState.playStone(Player.BLACK, Action.getInstance("H9"));
		gameState.playStone(Player.BLACK, Action.getInstance("J7"));
		gameState.playStone(Player.BLACK, Action.getInstance("E5"));
		gameState.playStone(Player.BLACK, Action.getInstance("F4"));
		gameState.playStone(Player.BLACK, Action.getInstance("G3"));
		gameState.playStone(Player.BLACK, Action.getInstance("D4"));
		gameState.playStone(Player.BLACK, Action.getInstance("E3"));
		gameState.playStone(Player.BLACK, Action.getInstance("B4"));
		gameState.playStone(Player.BLACK, Action.getInstance("C3"));
		gameState.playStone(Player.BLACK, Action.getInstance("D2"));
		gameState.playStone(Player.BLACK, Action.getInstance("E1"));
		
		gameState.playStone(Player.WHITE, Action.getInstance("H8"));
		gameState.playStone(Player.WHITE, Action.getInstance("H7"));
		gameState.playStone(Player.WHITE, Action.getInstance("D9"));
		gameState.playStone(Player.WHITE, Action.getInstance("D8"));
		gameState.playStone(Player.WHITE, Action.getInstance("E8"));
		
		gameState.playStone(Player.WHITE, Action.getInstance("A7"));
		gameState.playStone(Player.WHITE, Action.getInstance("A6"));
		gameState.playStone(Player.WHITE, Action.getInstance("B8"));
		gameState.playStone(Player.WHITE, Action.getInstance("B7"));
		gameState.playStone(Player.WHITE, Action.getInstance("B6"));
		gameState.playStone(Player.WHITE, Action.getInstance("C5"));
		gameState.playStone(Player.WHITE, Action.getInstance("D5"));
		gameState.playStone(Player.WHITE, Action.getInstance("D6"));
		
		gameState.playStone(Player.WHITE, Action.getInstance("A3"));
		gameState.playStone(Player.WHITE, Action.getInstance("B3"));
		
		gameState.playStone(Player.WHITE, Action.getInstance("B1"));
		gameState.playStone(Player.WHITE, Action.getInstance("F1"));
		
		System.out.println("State before move: ");
		System.out.println(gameState);
		assertTrue("Play by WHITE at H5 should not have failed.",gameState.playStone(Player.WHITE, Action.getInstance("H5")));
	}
}