src/main/java/ru/alphatech/icfpc/game/Run.java
author Azamat S. Kalimoulline <turtle@bazon.ru>
Sun, 19 Jun 2011 19:14:10 +0400
changeset 104 ecaee9f1a2be
parent 103 bb440d1c3ea4
child 105 57368a3d0b15
permissions -rw-r--r--
Call Count.
     1 /***********************************************
     2  * icfpc-2011
     3  * بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِِ
     4  * Time: 18.06.2011 11:37:46
     5  ***********************************************/
     6 package ru.alphatech.icfpc.game;
     7 
     8 import java.io.BufferedReader;
     9 import java.io.IOException;
    10 import java.io.InputStreamReader;
    11 
    12 import ru.alphatech.icfpc.cards.Attack;
    13 import ru.alphatech.icfpc.cards.Copy;
    14 import ru.alphatech.icfpc.cards.Dbl;
    15 import ru.alphatech.icfpc.cards.Dec;
    16 import ru.alphatech.icfpc.cards.Get;
    17 import ru.alphatech.icfpc.cards.Help;
    18 import ru.alphatech.icfpc.cards.I;
    19 import ru.alphatech.icfpc.cards.ICard;
    20 import ru.alphatech.icfpc.cards.Inc;
    21 import ru.alphatech.icfpc.cards.K;
    22 import ru.alphatech.icfpc.cards.Put;
    23 import ru.alphatech.icfpc.cards.Revive;
    24 import ru.alphatech.icfpc.cards.S;
    25 import ru.alphatech.icfpc.cards.Succ;
    26 import ru.alphatech.icfpc.cards.Zero;
    27 import ru.alphatech.icfpc.cards.Zombie;
    28 import ru.alphatech.icfpc.game.Batch.OperationType;
    29 import ru.alphatech.icfpc.game.strategy.IStrategy;
    30 import ru.alphatech.icfpc.game.strategy.SimplyStrategy;
    31 
    32 public class Run
    33 {
    34 	private static int callcount = 0;
    35 
    36 	private static boolean automodeapply = false;
    37 
    38 	private static boolean endgame = false;
    39 	
    40 	private static Player proponent = new Player();
    41 	
    42 	private static Player opponent = new Player();
    43 	
    44 	private static int registers[] = new int[4];
    45 	
    46 	static {
    47 		proponent.setMyOpponent(opponent);
    48 		opponent.setMyOpponent(proponent);
    49 		registers[0] = 0;
    50 		registers[1] = 1;
    51 		registers[2] = 2;
    52 		registers[3] = 3;
    53 	}
    54 	
    55 	private static IStrategy strategy = new SimplyStrategy();
    56 	
    57 	public static Slot getRegisterByIndex(int registerIndex){
    58 		return proponent.getSlot( registers[registerIndex] );
    59 	}
    60 	
    61 	public static int getRegisterSlotNum(int registerIndex ){
    62 		return registers[registerIndex];
    63 	}
    64 	
    65 	public static Player getOpponent(){
    66 		return opponent;
    67 	}
    68 	
    69 	public static Player getProponent(){
    70 		return proponent;
    71 	}
    72 	
    73 	private static void readOpponent() throws IOException
    74 	{
    75 		BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
    76 		String sTurnCase = breader.readLine();
    77 		String sCard = null;
    78 		String sSlot = null;
    79 		
    80 		OperationType operationType = null;
    81 		ICard card = null;
    82 		Slot slot = null;
    83 		
    84 		if("1".equals(sTurnCase))
    85 		{
    86 			sCard = breader.readLine();
    87 			sSlot = breader.readLine();
    88 			operationType = OperationType.CARD_TO_SLOT;
    89 		}
    90 		else if("2".equals(sTurnCase))
    91 		{
    92 			sSlot = breader.readLine();
    93 			sCard = breader.readLine();
    94 			operationType = OperationType.SLOT_TO_CARD;
    95 		}
    96 		else
    97 		{
    98 			// do nothing
    99 		}
   100 		
   101 		if(sTurnCase == null || sCard == null || sSlot == null)
   102 		{
   103 			endgame = true;
   104 			return;
   105 		}
   106 		
   107 		slot = opponent.getSlot(Integer.parseInt(sSlot));
   108 		for(ICard iCard: new ICard[]{
   109 				new Attack(),
   110 				new Copy(),
   111 				new Dbl(),
   112 				new Dec(),
   113 				new Get(),
   114 				new Help(),
   115 				new I(),
   116 				new Inc(),
   117 				new K(),
   118 				new Put(),
   119 				new Revive(),
   120 				new S(),
   121 				new Succ(),
   122 				new Zero(),
   123 				new Zombie(),
   124 				}){
   125 			if(sCard.equals(iCard.getName())){
   126 				card = iCard;
   127 				break;
   128 			}
   129 		}
   130 		Batch batch = new Batch(operationType, card, slot);
   131 		opponent.applyBatch(batch);
   132 	}
   133 	
   134 	private static void writeMove()
   135     {
   136 		Batch batch = strategy.move(proponent, opponent);
   137 		System.out.print(batch);
   138 		proponent.applyBatch(batch);
   139     }
   140 	
   141 	public static void resetCallCount()
   142 	{
   143 		callcount = 0;
   144 	}
   145 	
   146 	public static int incCallCount()
   147 	{
   148 		callcount++;
   149 		
   150 		return callcount;
   151 	}
   152 	
   153 	public static boolean getAutoMode()
   154 	{
   155 		return automodeapply;
   156 	}
   157 	
   158 	public static void main(String[] args) throws IOException
   159     {
   160 	    String playerNum = args[0];
   161 
   162 	    if("1".equals(playerNum))
   163 	    {
   164 	    	readOpponent();
   165 	    }
   166 	    
   167 	    while(!endgame)
   168 	    {
   169 		    writeMove();
   170 		    readOpponent();
   171 	    }
   172     }
   173 }