src/main/java/ru/alphatech/icfpc/game/Run.java
author indvdum
Sun, 19 Jun 2011 17:46:57 +0400
changeset 94 3b656d955291
parent 90 774e7ce00b5f
child 95 598cbc609683
permissions -rw-r--r--
*
     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 registerIdex){
    37 		return proponent.getSlot( registers[registerIdex] );
    38 	}
    39 	
    40 	public static Player getOpponent(){
    41 		return opponent;
    42 	}
    43 	
    44 	public static Player getProponent(){
    45 		return proponent;
    46 	}
    47 	
    48 	private static void readOpponent() throws IOException
    49 	{
    50 		BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
    51 		String turnCase = breader.readLine();
    52 		String card = null;
    53 		String slot = null;
    54 		
    55 		if("1".equals(turnCase))
    56 		{
    57 			card = breader.readLine();
    58 			slot = breader.readLine();
    59 		}
    60 		else if("2".equals(turnCase))
    61 		{
    62 			slot = breader.readLine();
    63 			card = breader.readLine();
    64 		}
    65 		else
    66 		{
    67 			// do nothing
    68 		}
    69 		
    70 		if(turnCase == null || card == null || slot == null)
    71 		{
    72 			endgame = true;
    73 			return;
    74 		}
    75 		
    76 		
    77 	}
    78 	
    79 	private static void writeMove()
    80     {
    81 		Batch batch = strategy.move(proponent, opponent);
    82 		System.out.print(batch);
    83 		proponent.applyBatch(batch);
    84     }
    85 	
    86 	public static boolean getAutoMode()
    87 	{
    88 		return automodeapply;
    89 	}
    90 	
    91 	public static void main(String[] args) throws IOException
    92     {
    93 	    String playerNum = args[0];
    94 
    95 	    if("1".equals(playerNum))
    96 	    {
    97 	    	readOpponent();
    98 	    }
    99 	    
   100 	    while(!endgame)
   101 	    {
   102 		    writeMove();
   103 		    readOpponent();
   104 	    }
   105     }
   106 }