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