src/main/java/ru/alphatech/icfpc/game/Run.java
changeset 98 19dba9e387ce
parent 96 8c40512777a1
child 99 60187fe9405d
child 102 cc814352ab43
     1.1 --- a/src/main/java/ru/alphatech/icfpc/game/Run.java	Sun Jun 19 17:53:59 2011 +0400
     1.2 +++ b/src/main/java/ru/alphatech/icfpc/game/Run.java	Sun Jun 19 18:42:07 2011 +0400
     1.3 @@ -8,22 +8,37 @@
     1.4  import java.io.BufferedReader;
     1.5  import java.io.IOException;
     1.6  import java.io.InputStreamReader;
     1.7 -import java.util.LinkedList;
     1.8 -import java.util.List;
     1.9  
    1.10 +import ru.alphatech.icfpc.cards.Attack;
    1.11 +import ru.alphatech.icfpc.cards.Copy;
    1.12 +import ru.alphatech.icfpc.cards.Dbl;
    1.13 +import ru.alphatech.icfpc.cards.Dec;
    1.14 +import ru.alphatech.icfpc.cards.Get;
    1.15 +import ru.alphatech.icfpc.cards.Help;
    1.16 +import ru.alphatech.icfpc.cards.I;
    1.17 +import ru.alphatech.icfpc.cards.ICard;
    1.18 +import ru.alphatech.icfpc.cards.Inc;
    1.19 +import ru.alphatech.icfpc.cards.K;
    1.20 +import ru.alphatech.icfpc.cards.Put;
    1.21 +import ru.alphatech.icfpc.cards.Revive;
    1.22 +import ru.alphatech.icfpc.cards.S;
    1.23 +import ru.alphatech.icfpc.cards.Succ;
    1.24 +import ru.alphatech.icfpc.cards.Zero;
    1.25 +import ru.alphatech.icfpc.cards.Zombie;
    1.26 +import ru.alphatech.icfpc.game.Batch.OperationType;
    1.27  import ru.alphatech.icfpc.game.strategy.IStrategy;
    1.28  import ru.alphatech.icfpc.game.strategy.SimplyStrategy;
    1.29  
    1.30  public class Run
    1.31  {
    1.32 +	private static boolean automodeapply = false;
    1.33 +
    1.34  	private static boolean endgame = false;
    1.35  	
    1.36  	private static Player proponent = new Player();
    1.37  	
    1.38  	private static Player opponent = new Player();
    1.39  	
    1.40 -	private static LinkedList<Batch> batches = new LinkedList<Batch>();
    1.41 -	
    1.42  	private static int registers[] = new int[4];
    1.43  	
    1.44  	static {
    1.45 @@ -35,16 +50,12 @@
    1.46  	
    1.47  	private static IStrategy strategy = new SimplyStrategy();
    1.48  	
    1.49 -	public static Slot getRegisterByIndex(int registerIdex){
    1.50 -		return proponent.getSlot( registers[registerIdex] );
    1.51 +	public static Slot getRegisterByIndex(int registerIndex){
    1.52 +		return proponent.getSlot( registers[registerIndex] );
    1.53  	}
    1.54  	
    1.55 -	public static void clearBatcher(){
    1.56 -		batches.removeAll(batches);
    1.57 -	}
    1.58 -	
    1.59 -	public static void addBatcher(List<Batch> batches){
    1.60 -		batches.addAll(batches);
    1.61 +	public static int getRegisterSlotNum(int registerIndex ){
    1.62 +		return registers[registerIndex];
    1.63  	}
    1.64  	
    1.65  	public static Player getOpponent(){
    1.66 @@ -58,36 +69,76 @@
    1.67  	private static void readOpponent() throws IOException
    1.68  	{
    1.69  		BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
    1.70 -		String turnCase = breader.readLine();
    1.71 -		String card = null;
    1.72 -		String slot = null;
    1.73 +		String sTurnCase = breader.readLine();
    1.74 +		String sCard = null;
    1.75 +		String sSlot = null;
    1.76  		
    1.77 -		if("1".equals(turnCase))
    1.78 +		OperationType operationType = null;
    1.79 +		ICard card = null;
    1.80 +		Slot slot = null;
    1.81 +		
    1.82 +		if("1".equals(sTurnCase))
    1.83  		{
    1.84 -			card = breader.readLine();
    1.85 -			slot = breader.readLine();
    1.86 +			sCard = breader.readLine();
    1.87 +			sSlot = breader.readLine();
    1.88 +			operationType = OperationType.CARD_TO_SLOT;
    1.89  		}
    1.90 -		else if("2".equals(turnCase))
    1.91 +		else if("2".equals(sTurnCase))
    1.92  		{
    1.93 -			slot = breader.readLine();
    1.94 -			card = breader.readLine();
    1.95 +			sSlot = breader.readLine();
    1.96 +			sCard = breader.readLine();
    1.97 +			operationType = OperationType.SLOT_TO_CARD;
    1.98  		}
    1.99  		else
   1.100  		{
   1.101  			// do nothing
   1.102  		}
   1.103  		
   1.104 -		if(turnCase == null || card == null || slot == null)
   1.105 +		if(sTurnCase == null || sCard == null || sSlot == null)
   1.106  		{
   1.107  			endgame = true;
   1.108 +			return;
   1.109  		}
   1.110 +		
   1.111 +		slot = opponent.getSlot(Integer.parseInt(sSlot));
   1.112 +		for(ICard iCard: new ICard[]{
   1.113 +				new Attack(),
   1.114 +				new Copy(),
   1.115 +				new Dbl(),
   1.116 +				new Dec(),
   1.117 +				new Get(),
   1.118 +				new Help(),
   1.119 +				new I(),
   1.120 +				new Inc(),
   1.121 +				new K(),
   1.122 +				new Put(),
   1.123 +				new Revive(),
   1.124 +				new S(),
   1.125 +				new Succ(),
   1.126 +				new Zero(),
   1.127 +				new Zombie(),
   1.128 +				}){
   1.129 +			if(sCard.equals(iCard.getName())){
   1.130 +				card = iCard;
   1.131 +				break;
   1.132 +			}
   1.133 +		}
   1.134 +		Batch batch = new Batch(operationType, card, slot);
   1.135 +		opponent.applyBatch(batch);
   1.136  	}
   1.137  	
   1.138  	private static void writeMove()
   1.139      {
   1.140 -		strategy.moving(proponent, opponent, System.out);
   1.141 +		Batch batch = strategy.move(proponent, opponent);
   1.142 +		System.out.print(batch);
   1.143 +		proponent.applyBatch(batch);
   1.144      }
   1.145  	
   1.146 +	public static boolean getAutoMode()
   1.147 +	{
   1.148 +		return automodeapply;
   1.149 +	}
   1.150 +	
   1.151  	public static void main(String[] args) throws IOException
   1.152      {
   1.153  	    String playerNum = args[0];