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