package net.woodyfolsom.msproj;

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

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.antlr.runtime.RecognitionException;
import org.junit.Test;

public class GameScoreTest {

	@Test
	public void testGetAggregateScoreZero() {
		GameResult gameScore = new GameResult(0, 0, 19, 0, true);
		assertEquals(gameScore.getNormalizedZeroScore(),
				gameScore.getNormalizedScore());
	}

	@Test
	public void testGetAggregateScoreBlackWinsNoKomi() {
		GameResult gameScore = new GameResult(25, 2, 19, 0, true);
		assertEquals(407, gameScore.getNormalizedScore());
	}

	@Test
	public void testGetAggregateScoreWhiteWinsWithKomi() {
		GameResult gameScore = new GameResult(10, 12, 19, 6.5, true);
		assertEquals(357, gameScore.getNormalizedScore());
	}

	@Test
	public void testScoreEndGame() throws IOException, RecognitionException {
		//test case from:
		//http://www.online-go.com/faq.php?name=rules
		GameRecord gameRecord = Referee.replay(new FileInputStream(new File("data/test/ScoreTest.sgf")));
		GameState gameState = gameRecord.getGameState(gameRecord.getNumTurns());
		GameConfig gameConfig = gameState.getGameConfig();
		
		System.out.println(gameState);
		System.out.println(gameState.getResult());
		
		GameState gameStateCopy = new GameState(gameState);
		TerritoryMarker.markTerritory(gameStateCopy.getGameBoard());
		System.out.println(gameStateCopy);
		
		assertEquals(9,gameConfig.getSize());
		assertEquals(6.0,gameConfig.getKomi(),0.1);
		
		assertTrue(gameState.isTerminal());
		assertTrue(gameState.getResult().isWinner(Player.WHITE));
	}
}