src/main/java/ru/alphatech/icfpc/game/Run.java
author Azamat S. Kalimoulline <turtle@bazon.ru>
Sun, 19 Jun 2011 14:30:33 +0400
changeset 65 2c8b98d4efb8
parent 55 26d05bc45f1d
child 78 7eacf1e21213
child 80 fcdce54b2f25
permissions -rw-r--r--
Merge with 7b60d53f6933b3f59077116357f17b4674c9abfc
     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 endgame = false;
    20 	
    21 	private static Player proponent = new Player();
    22 	
    23 	private static Player opponent = new Player();
    24 	
    25 	private static LinkedList<Batch> batches = new LinkedList<Batch>();
    26 	
    27 	private static int registers[] = new int[4];
    28 	
    29 	static {
    30 		registers[0] = 0;
    31 		registers[1] = 1;
    32 		registers[2] = 2;
    33 		registers[3] = 3;
    34 	}
    35 	
    36 	private static IStrategy strategy = new SimplyStrategy();
    37 	
    38 	public static Slot getRegisterByIndex(int registerIdex){
    39 		return proponent.getSlot( registers[registerIdex] );
    40 	}
    41 	
    42 	public static void clearBatcher(){
    43 		batches.removeAll(batches);
    44 	}
    45 	
    46 	public static void addBatcher(List<Batch> batches){
    47 		batches.addAll(batches);
    48 	}
    49 	
    50 	public static Player getOpponent(){
    51 		return opponent;
    52 	}
    53 	
    54 	public static Player getProponent(){
    55 		return proponent;
    56 	}
    57 	
    58 	private static void readOpponent() throws IOException
    59 	{
    60 		BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
    61 		String turnCase = breader.readLine();
    62 		String card = null;
    63 		String slot = null;
    64 		
    65 		if("1".equals(turnCase))
    66 		{
    67 			card = breader.readLine();
    68 			slot = breader.readLine();
    69 		}
    70 		else if("2".equals(turnCase))
    71 		{
    72 			slot = breader.readLine();
    73 			card = breader.readLine();
    74 		}
    75 		else
    76 		{
    77 			// do nothing
    78 		}
    79 		
    80 		if(turnCase == null || card == null || slot == null)
    81 		{
    82 			endgame = true;
    83 		}
    84 	}
    85 	
    86 	private static void writeMove()
    87     {
    88 		strategy.moving(proponent, opponent, System.out);
    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 }