src/main/java/ru/alphatech/icfpc/game/Player.java
author Azamat S. Kalimoulline <turtle@bazon.ru>
Tue, 21 Jun 2011 11:55:31 +0400
changeset 140 9ddaa68cccae
parent 127 57ee53a3cf56
permissions -rw-r--r--
Cards bugs revealed.
     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 int playerNumber = -1;
    12 
    13 	private Slot[] slots = new Slot[256];
    14 	private Player myOpponent = null;
    15 
    16 	public Player()
    17     {
    18 		for(int i = 0; i <= 255; i++)
    19 		{
    20 			slots[i] = new Slot(i);
    21 		}
    22     }
    23 	
    24 	public int getPlayerNumber() {
    25 		return playerNumber;
    26 	}
    27 	
    28 	public void setPlayerNumber(int playerNumber) {
    29 		this.playerNumber = playerNumber;
    30 	}
    31 
    32 	public Player getMyOpponent() {
    33 		return myOpponent;
    34 	}
    35 	
    36 	public void setMyOpponent(Player myOpponent) {
    37 		this.myOpponent = myOpponent;
    38 	}
    39 	
    40 	public Slot getSlot(int i)
    41 	{
    42 		return slots[i];
    43 	}
    44 	
    45 	public PlayerStatistic getStatistic(){
    46 		throw new RuntimeException("Not implemented yet.");
    47 	}
    48 	
    49 	public void applyBatch(Batch batch){
    50 		Run.setAutoMode(false);
    51 		Run.resetCallCount();
    52 		try{
    53 			switch(batch.operationType){
    54 			case CARD_TO_SLOT:
    55 				IValue value = getSlot(batch.slot.getId()).getValue();
    56 				
    57 				if(value instanceof Zero)
    58 				{
    59 					value = new Value(0);
    60 				}
    61 				
    62 				if(batch.card instanceof Zero)
    63 				{
    64 					batch.card = (ICard) new Value(0);
    65 				}
    66 
    67 				getSlot(batch.slot.getId()).putValue(batch.card.returnValue(value, this, myOpponent));
    68 				break;
    69 			case SLOT_TO_CARD:
    70 				IValue valueC = batch.card;
    71 				
    72 				if(valueC instanceof Zero)
    73 				{
    74 					valueC = new Value(0);
    75 				}
    76 
    77 				getSlot(batch.slot.getId()).putValue(getSlot(batch.slot.getId()).getValue().returnValue(valueC, this, myOpponent));
    78 				break;
    79 			}
    80 		} catch (ICFPCException exception){
    81 			getSlot(batch.slot.getId()).putValue(new I());
    82 		}
    83 		Run.setAutoMode(true);
    84 		Run.resetCallCount();
    85 		for(Slot slot: myOpponent.slots){
    86 			if(slot.isZombie()){
    87 				slot.getValue().returnValue(new I(), myOpponent, myOpponent.getMyOpponent());
    88 			}
    89 		}
    90 	}
    91 	
    92 }