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