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