/***********************************************
 * icfpc-2011
 * بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِِ
 * Time: 18.06.2011 11:37:46
 ***********************************************/
package ru.alphatech.icfpc.game;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import ru.alphatech.icfpc.game.strategy.IStrategy;
import ru.alphatech.icfpc.game.strategy.SimplyStrategy;

public class Run
{
	private static boolean automodeapply = false;

	private static boolean endgame = false;
	
	private static Player proponent = new Player();
	
	private static Player opponent = new Player();
	
	private static int registers[] = new int[4];
	
	static {
		registers[0] = 0;
		registers[1] = 1;
		registers[2] = 2;
		registers[3] = 3;
	}
	
	private static IStrategy strategy = new SimplyStrategy();
	
	public static Slot getRegisterByIndex(int registerIdex){
		return proponent.getSlot( registers[registerIdex] );
	}
	
	public static Player getOpponent(){
		return opponent;
	}
	
	public static Player getProponent(){
		return proponent;
	}
	
	private static void readOpponent() throws IOException
	{
		BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
		String turnCase = breader.readLine();
		String card = null;
		String slot = null;
		
		if("1".equals(turnCase))
		{
			card = breader.readLine();
			slot = breader.readLine();
		}
		else if("2".equals(turnCase))
		{
			slot = breader.readLine();
			card = breader.readLine();
		}
		else
		{
			// do nothing
		}
		
		if(turnCase == null || card == null || slot == null)
		{
			endgame = true;
			return;
		}
		
		
	}
	
	private static void writeMove()
    {
		Batch batch = strategy.move(proponent, opponent);
		System.out.print(batch);
		proponent.applyBatch(batch);
    }
	
	public static boolean getAutoMode()
	{
		return automodeapply;
	}
	
	public static void main(String[] args) throws IOException
    {
	    String playerNum = args[0];

	    if("1".equals(playerNum))
	    {
	    	readOpponent();
	    }
	    
	    while(!endgame)
	    {
		    writeMove();
		    readOpponent();
	    }
    }
}
