package net.woodyfolsom.msproj.policy;

import static org.junit.Assert.assertEquals;
import net.woodyfolsom.msproj.Action;
import net.woodyfolsom.msproj.GameConfig;
import net.woodyfolsom.msproj.GameState;
import net.woodyfolsom.msproj.Player;

import org.junit.Test;

public class AlphaBetaTest {
	@Test
	public void testGenmoveAsW() {
		Policy treeSearch = new AlphaBeta();
		GameConfig gameConfig = new GameConfig(6);
		GameState gameState = new GameState(gameConfig);
		gameState.playStone(Player.BLACK, Action.getInstance("PASS"));
		gameState.playStone(Player.WHITE, Action.getInstance("A2"));
		gameState.playStone(Player.BLACK, Action.getInstance("PASS"));
		gameState.playStone(Player.WHITE, Action.getInstance("B1"));
		gameState.playStone(Player.BLACK, Action.getInstance("PASS"));
		gameState.playStone(Player.WHITE, Action.getInstance("C2"));
		gameState.playStone(Player.BLACK, Action.getInstance("B2"));

		Action move = treeSearch.getAction(gameConfig, gameState, Player.WHITE);
		
		System.out.println(gameState);

		System.out.println("Generated move: " + move);
		System.out.println("NumStateEvaluations: " + treeSearch.getNumStateEvaluations());
		
		assertEquals(Action.getInstance("B3"), move);
		gameState.playStone(Player.WHITE, move);
		System.out.println("Final board state:");
		System.out.println(gameState);
	}

	@Test
	public void testGenmoveAsB() {
		Policy treeSearch = new AlphaBeta();
		GameConfig gameConfig = new GameConfig(6);
		GameState gameState = new GameState(gameConfig);
		gameState.playStone(Player.BLACK, Action.getInstance("A2"));
		gameState.playStone(Player.WHITE, Action.getInstance("PASS"));
		gameState.playStone(Player.BLACK, Action.getInstance("B1"));
		gameState.playStone(Player.WHITE, Action.getInstance("PASS"));
		gameState.playStone(Player.BLACK, Action.getInstance("C2"));
		gameState.playStone(Player.WHITE, Action.getInstance("B2"));

		Action move = treeSearch.getAction(gameConfig, gameState, Player.BLACK);
		
		System.out.println(gameState);

		System.out.println("Generated move: " + move);
		System.out.println("NumStateEvaluations: " + treeSearch.getNumStateEvaluations());
		
		assertEquals("Expected B3 but was: " + move, Action.getInstance("B3"), move);
		gameState.playStone(Player.BLACK, move);
		
		System.out.println("Final board state:");
		System.out.println(gameState);
	}
}