src/main/java/ru/alphatech/icfpc/game/Run.java
author Azamat S. Kalimoulline <turtle@bazon.ru>
Sun, 19 Jun 2011 19:13:07 +0400
changeset 102 cc814352ab43
parent 96 8c40512777a1
child 103 bb440d1c3ea4
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 		registers[0] = 0;
    48 		registers[1] = 1;
    49 		registers[2] = 2;
    50 		registers[3] = 3;
    51 	}
    52 	
    53 	private static IStrategy strategy = new SimplyStrategy();
    54 	
    55 	public static Slot getRegisterByIndex(int registerIndex){
    56 		return proponent.getSlot( registers[registerIndex] );
    57 	}
    58 	
    59 	public static int getRegisterSlotNum(int registerIndex ){
    60 		return registers[registerIndex];
    61 	}
    62 	
    63 	public static Player getOpponent(){
    64 		return opponent;
    65 	}
    66 	
    67 	public static Player getProponent(){
    68 		return proponent;
    69 	}
    70 	
    71 	private static void readOpponent() throws IOException
    72 	{
    73 		BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
    74 		String sTurnCase = breader.readLine();
    75 		String sCard = null;
    76 		String sSlot = null;
    77 		
    78 		OperationType operationType = null;
    79 		ICard card = null;
    80 		Slot slot = null;
    81 		
    82 		if("1".equals(sTurnCase))
    83 		{
    84 			sCard = breader.readLine();
    85 			sSlot = breader.readLine();
    86 			operationType = OperationType.CARD_TO_SLOT;
    87 		}
    88 		else if("2".equals(sTurnCase))
    89 		{
    90 			sSlot = breader.readLine();
    91 			sCard = breader.readLine();
    92 			operationType = OperationType.SLOT_TO_CARD;
    93 		}
    94 		else
    95 		{
    96 			// do nothing
    97 		}
    98 		
    99 		if(sTurnCase == null || sCard == null || sSlot == null)
   100 		{
   101 			endgame = true;
   102 			return;
   103 		}
   104 		
   105 		slot = opponent.getSlot(Integer.parseInt(sSlot));
   106 		for(ICard iCard: new ICard[]{
   107 				new Attack(),
   108 				new Copy(),
   109 				new Dbl(),
   110 				new Dec(),
   111 				new Get(),
   112 				new Help(),
   113 				new I(),
   114 				new Inc(),
   115 				new K(),
   116 				new Put(),
   117 				new Revive(),
   118 				new S(),
   119 				new Succ(),
   120 				new Zero(),
   121 				new Zombie(),
   122 				}){
   123 			if(sCard.equals(iCard.getName())){
   124 				card = iCard;
   125 				break;
   126 			}
   127 		}
   128 		Batch batch = new Batch(operationType, card, slot);
   129 		opponent.applyBatch(batch);
   130 	}
   131 	
   132 	private static void writeMove()
   133     {
   134 		Batch batch = strategy.move(proponent, opponent);
   135 		System.out.print(batch);
   136 		proponent.applyBatch(batch);
   137     }
   138 	
   139 	public static void resetCallCount()
   140 	{
   141 		callcount = 0;
   142 	}
   143 	
   144 	public static int incCallCount()
   145 	{
   146 		callcount++;
   147 		
   148 		return callcount;
   149 	}
   150 	
   151 	public static boolean getAutoMode()
   152 	{
   153 		return automodeapply;
   154 	}
   155 	
   156 	public static void main(String[] args) throws IOException
   157     {
   158 	    String playerNum = args[0];
   159 
   160 	    if("1".equals(playerNum))
   161 	    {
   162 	    	readOpponent();
   163 	    }
   164 	    
   165 	    while(!endgame)
   166 	    {
   167 		    writeMove();
   168 		    readOpponent();
   169 	    }
   170     }
   171 }