package ru.alphatech.icfpc.game;

import ru.alphatech.icfpc.cards.I;



public class Player
{
	private Slot[] slots = new Slot[256];
	private Player myOpponent = null;

	public Player()
    {
		for(int i = 0; i <= 255; i++)
		{
			slots[i] = new Slot(i);
		}
    }
	
	public Player getMyOpponent() {
		return myOpponent;
	}
	
	public void setMyOpponent(Player myOpponent) {
		this.myOpponent = myOpponent;
	}
	
	public Slot getSlot(int i)
	{
		return slots[i];
	}
	
	public PlayerStatistic getStatistic(){
		throw new RuntimeException("Not impilemented yet.");
	}
	
	public void applyBatch(Batch batch){
		Run.setAutoMode(false);
		Run.resetCallCount();
		try{
			switch(batch.operationType){
			case CARD_TO_SLOT:
				batch.card.returnValue(getSlot(batch.slot.getId()).getValue(), this, myOpponent);
				break;
			case SLOT_TO_CARD:
				getSlot(batch.slot.getId()).getValue().returnValue(batch.card, this, myOpponent);
				break;
			}
		} catch (ICFPCException exception){
			getSlot(batch.slot.getId()).putValue(new I());
		}
		Run.setAutoMode(true);
		Run.resetCallCount();
		for(Slot slot: myOpponent.slots){
			if(slot.isZombie()){
				slot.getValue().returnValue(new I(), myOpponent, myOpponent.getMyOpponent());
			}
		}
	}
	
}
