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