src/main/java/ru/alphatech/icfpc/game/Run.java
author indvdum
Sun, 19 Jun 2011 18:55:26 +0400
changeset 99 60187fe9405d
parent 96 8c40512777a1
child 101 4bb458c3548e
child 103 bb440d1c3ea4
permissions -rw-r--r--
+ action analyzer
     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 boolean automodeapply = false;
    35 
    36 	private static boolean endgame = false;
    37 	
    38 	private static Player proponent = new Player();
    39 	
    40 	private static Player opponent = new Player();
    41 	
    42 	private static int registers[] = new int[4];
    43 	
    44 	static {
    45 		proponent.setMyOpponent(opponent);
    46 		opponent.setMyOpponent(proponent);
    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 boolean getAutoMode()
   140 	{
   141 		return automodeapply;
   142 	}
   143 	
   144 	public static void main(String[] args) throws IOException
   145     {
   146 	    String playerNum = args[0];
   147 
   148 	    if("1".equals(playerNum))
   149 	    {
   150 	    	readOpponent();
   151 	    }
   152 	    
   153 	    while(!endgame)
   154 	    {
   155 		    writeMove();
   156 		    readOpponent();
   157 	    }
   158     }
   159 }