package net.woodyfolsom.msproj;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

public class LatexWriter {

	public static void write(OutputStream os, GameRecord gameRecord,
			int turnNumber) throws IOException {
		OutputStreamWriter writer = new OutputStreamWriter(os);

		int boardSize = gameRecord.getGameConfig().getSize();

		writer.write("\\begin{figure}[h]\n");
		writer.write("\\black{");
		boolean firstMove = true;
		for (int turn = 1; turn <= gameRecord.getNumTurns(); turn+=2) {
			if (!firstMove) {
				writer.write(",");
			}
			writer.write(gameRecord.getMove(turn).toLatex(boardSize));
			firstMove = false;
		}
		writer.write("}\n");
		
		writer.write("\\white{");
		firstMove = true;
		for (int turn = 2; turn <= gameRecord.getNumTurns(); turn+=2) {
			if (!firstMove) {
				writer.write(",");
			}
			writer.write(gameRecord.getMove(turn).toLatex(boardSize));
			firstMove = false;
		}
		writer.write("}\n");
		
		writer.write("\\begin{center}\n");
		writer.write("\\gobansize{" + boardSize + "}\n");
		writer.write("\\shortstack{\\showfullgoban\\\\"
				+ gameRecord.getResult().getFullText() + "}\n");
		writer.write("\\end{center}\n");
		writer.write("\\end{figure}\n");
		writer.flush();
	}
}