src/main/java/ru/alphatech/icfpc/game/Player.java
author akhmetovlz
Sun, 19 Jun 2011 21:09:52 +0400
changeset 111 0b8b3ec13a82
parent 110 d6c063577f0d
child 122 845c89fa268e
permissions -rw-r--r--
(no commit message)
turtle@12
     1
package ru.alphatech.icfpc.game;
0-range@4
     2
indvdum@99
     3
import ru.alphatech.icfpc.cards.I;
akhmetovlz@110
     4
import ru.alphatech.icfpc.cards.ICard;
akhmetovlz@110
     5
import ru.alphatech.icfpc.cards.Zero;
indvdum@99
     6
akhmetovlz@17
     7
0-range@4
     8
turtle@11
     9
public class Player
0-range@4
    10
{
turtle@28
    11
	private Slot[] slots = new Slot[256];
indvdum@99
    12
	private Player myOpponent = null;
indvdum@99
    13
turtle@28
    14
	public Player()
turtle@28
    15
    {
indvdum@106
    16
		for(int i = 0; i <= 255; i++)
turtle@28
    17
		{
indvdum@80
    18
			slots[i] = new Slot(i);
turtle@28
    19
		}
turtle@28
    20
    }
turtle@28
    21
	
indvdum@99
    22
	public Player getMyOpponent() {
indvdum@99
    23
		return myOpponent;
indvdum@99
    24
	}
indvdum@99
    25
	
indvdum@99
    26
	public void setMyOpponent(Player myOpponent) {
indvdum@99
    27
		this.myOpponent = myOpponent;
indvdum@99
    28
	}
indvdum@99
    29
	
turtle@11
    30
	public Slot getSlot(int i)
turtle@11
    31
	{
turtle@28
    32
		return slots[i];
turtle@11
    33
	}
akhmetovlz@17
    34
	
akhmetovlz@19
    35
	public PlayerStatistic getStatistic(){
akhmetovlz@19
    36
		throw new RuntimeException("Not impilemented yet.");
akhmetovlz@19
    37
	}
akhmetovlz@30
    38
	
indvdum@90
    39
	public void applyBatch(Batch batch){
indvdum@106
    40
		Run.setAutoMode(false);
indvdum@106
    41
		Run.resetCallCount();
indvdum@106
    42
		try{
indvdum@106
    43
			switch(batch.operationType){
indvdum@106
    44
			case CARD_TO_SLOT:
akhmetovlz@110
    45
				IValue value = getSlot(batch.slot.getId()).getValue();
akhmetovlz@110
    46
				
akhmetovlz@110
    47
				if(value instanceof Zero)
akhmetovlz@110
    48
				{
akhmetovlz@110
    49
					value = new Value(0);
akhmetovlz@110
    50
				}
akhmetovlz@110
    51
				
akhmetovlz@110
    52
				if(batch.card instanceof Zero)
akhmetovlz@110
    53
				{
akhmetovlz@110
    54
					batch.card = (ICard) new Value(0);
akhmetovlz@110
    55
				}
akhmetovlz@110
    56
akhmetovlz@110
    57
				batch.card.returnValue(value, this, myOpponent);
indvdum@106
    58
				break;
indvdum@106
    59
			case SLOT_TO_CARD:
indvdum@106
    60
				getSlot(batch.slot.getId()).getValue().returnValue(batch.card, this, myOpponent);
indvdum@106
    61
				break;
indvdum@106
    62
			}
indvdum@106
    63
		} catch (ICFPCException exception){
indvdum@106
    64
			getSlot(batch.slot.getId()).putValue(new I());
indvdum@106
    65
		}
indvdum@106
    66
		Run.setAutoMode(true);
indvdum@106
    67
		Run.resetCallCount();
indvdum@106
    68
		for(Slot slot: myOpponent.slots){
indvdum@106
    69
			if(slot.isZombie()){
indvdum@106
    70
				slot.getValue().returnValue(new I(), myOpponent, myOpponent.getMyOpponent());
indvdum@106
    71
			}
indvdum@99
    72
		}
indvdum@90
    73
	}
akhmetovlz@30
    74
	
0-range@4
    75
}