src/main/java/ru/alphatech/icfpc/game/Run.java
author akhmetovlz
Sun, 19 Jun 2011 17:46:07 +0400
changeset 93 901ceef564fd
parent 92 2e69298ad664
parent 90 774e7ce00b5f
child 95 598cbc609683
permissions -rw-r--r--
Merge with 179dd516b115f205d68afe1b626e449e2843b54c
     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.game.strategy.IStrategy;
    13 import ru.alphatech.icfpc.game.strategy.SimplyStrategy;
    14 
    15 public class Run
    16 {
    17 	private static boolean automodeapply = false;
    18 
    19 	private static boolean endgame = false;
    20 	
    21 	private static Player proponent = new Player();
    22 	
    23 	private static Player opponent = new Player();
    24 	
    25 	private static int registers[] = new int[4];
    26 	
    27 	static {
    28 		registers[0] = 0;
    29 		registers[1] = 1;
    30 		registers[2] = 2;
    31 		registers[3] = 3;
    32 	}
    33 	
    34 	private static IStrategy strategy = new SimplyStrategy();
    35 	
    36 	public static Slot getRegisterByIndex(int registerIndex){
    37 		return proponent.getSlot( registers[registerIndex] );
    38 	}
    39 	
    40 	public static int getRegisterSlotNum(int registerIndex ){
    41 		return registers[registerIndex];
    42 	}
    43 	
    44 	public static Player getOpponent(){
    45 		return opponent;
    46 	}
    47 	
    48 	public static Player getProponent(){
    49 		return proponent;
    50 	}
    51 	
    52 	private static void readOpponent() throws IOException
    53 	{
    54 		BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
    55 		String turnCase = breader.readLine();
    56 		String card = null;
    57 		String slot = null;
    58 		
    59 		if("1".equals(turnCase))
    60 		{
    61 			card = breader.readLine();
    62 			slot = breader.readLine();
    63 		}
    64 		else if("2".equals(turnCase))
    65 		{
    66 			slot = breader.readLine();
    67 			card = breader.readLine();
    68 		}
    69 		else
    70 		{
    71 			// do nothing
    72 		}
    73 		
    74 		if(turnCase == null || card == null || slot == null)
    75 		{
    76 			endgame = true;
    77 		}
    78 	}
    79 	
    80 	private static void writeMove()
    81     {
    82 		Batch batch = strategy.move(proponent, opponent);
    83 		System.out.print(batch);
    84 		proponent.applyBatch(batch);
    85     }
    86 	
    87 	public static boolean getAutoMode()
    88 	{
    89 		return automodeapply;
    90 	}
    91 	
    92 	public static void main(String[] args) throws IOException
    93     {
    94 	    String playerNum = args[0];
    95 
    96 	    if("1".equals(playerNum))
    97 	    {
    98 	    	readOpponent();
    99 	    }
   100 	    
   101 	    while(!endgame)
   102 	    {
   103 		    writeMove();
   104 		    readOpponent();
   105 	    }
   106     }
   107 }