package net.woodyfolsom.msproj;

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

import org.junit.Test;

public class LegalMoveTest {
	@Test
	public void testLegalMove1Liberty() {
		GameConfig gameConfig = new GameConfig(5);
		GameState gameState = new GameState(gameConfig);
		gameState.playStone(Player.BLACK, Action.getInstance("A2"));
		assertEquals(Player.WHITE, gameState.getPlayerToMove());
		gameState.playStone(Player.WHITE, Action.PASS);
		
		gameState.playStone(Player.BLACK, Action.getInstance("B3"));
		gameState.playStone(Player.WHITE, Action.PASS);
		
		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
		GameConfig gameConfig = new GameConfig(9);
		GameState gameState = new GameState(gameConfig);
		
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("G5")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("G7")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("F6")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("H6")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("C7")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("D7")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("E7")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("F7")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("G8")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("H9")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("J7")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("E5")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("F4")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("G3")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("D4")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("E3")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("B4")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("C3")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("D2")));
		assertTrue(gameState.placeStone(Player.BLACK, Action.getInstance("E1")));
		
		assertTrue(gameState.placeStone(Player.WHITE, Action.getInstance("H8")));
		assertTrue(gameState.placeStone(Player.WHITE, Action.getInstance("H7")));
		assertTrue(gameState.placeStone(Player.WHITE, Action.getInstance("D9")));
		assertTrue(gameState.placeStone(Player.WHITE, Action.getInstance("D8")));
		assertTrue(gameState.placeStone(Player.WHITE, Action.getInstance("E8")));
		
		assertTrue(gameState.placeStone(Player.WHITE, Action.getInstance("A7")));
		assertTrue(gameState.placeStone(Player.WHITE, Action.getInstance("A6")));
		assertTrue(gameState.placeStone(Player.WHITE, Action.getInstance("B8")));
		assertTrue(gameState.placeStone(Player.WHITE, Action.getInstance("B7")));
		assertTrue(gameState.placeStone(Player.WHITE, Action.getInstance("B6")));
		assertTrue(gameState.placeStone(Player.WHITE, Action.getInstance("C5")));
		assertTrue(gameState.placeStone(Player.WHITE, Action.getInstance("D5")));
		assertTrue(gameState.placeStone(Player.WHITE, Action.getInstance("D6")));
		
		assertTrue(gameState.placeStone(Player.WHITE, Action.getInstance("A3")));
		assertTrue(gameState.placeStone(Player.WHITE, Action.getInstance("B3")));
		
		assertTrue(gameState.placeStone(Player.WHITE, Action.getInstance("B1")));
		assertTrue(gameState.placeStone(Player.WHITE, Action.getInstance("F1")));
		
		assertTrue(gameState.playStone(Player.BLACK, Action.PASS));
		
		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")));
	}
}