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--
*
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;
turtle@14
    11
indvdum@55
    12
import ru.alphatech.icfpc.game.strategy.IStrategy;
indvdum@55
    13
import ru.alphatech.icfpc.game.strategy.SimplyStrategy;
indvdum@55
    14
turtle@13
    15
public class Run
turtle@13
    16
{
turtle@78
    17
	private static boolean automodeapply = false;
turtle@78
    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 int registers[] = new int[4];
akhmetovlz@48
    26
	
akhmetovlz@48
    27
	static {
akhmetovlz@48
    28
		registers[0] = 0;
akhmetovlz@48
    29
		registers[1] = 1;
akhmetovlz@48
    30
		registers[2] = 2;
akhmetovlz@48
    31
		registers[3] = 3;
akhmetovlz@48
    32
	}
akhmetovlz@48
    33
	
indvdum@55
    34
	private static IStrategy strategy = new SimplyStrategy();
indvdum@55
    35
	
akhmetovlz@48
    36
	public static Slot getRegisterByIndex(int registerIdex){
akhmetovlz@48
    37
		return proponent.getSlot( registers[registerIdex] );
akhmetovlz@48
    38
	}
akhmetovlz@48
    39
	
akhmetovlz@48
    40
	public static Player getOpponent(){
akhmetovlz@48
    41
		return opponent;
akhmetovlz@48
    42
	}
akhmetovlz@48
    43
	
akhmetovlz@48
    44
	public static Player getProponent(){
akhmetovlz@48
    45
		return proponent;
akhmetovlz@31
    46
	}
akhmetovlz@31
    47
	
turtle@14
    48
	private static void readOpponent() throws IOException
turtle@14
    49
	{
turtle@14
    50
		BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
turtle@29
    51
		String turnCase = breader.readLine();
turtle@29
    52
		String card = null;
turtle@29
    53
		String slot = null;
turtle@14
    54
		
turtle@29
    55
		if("1".equals(turnCase))
turtle@29
    56
		{
turtle@29
    57
			card = breader.readLine();
turtle@29
    58
			slot = breader.readLine();
turtle@29
    59
		}
turtle@29
    60
		else if("2".equals(turnCase))
turtle@29
    61
		{
turtle@29
    62
			slot = breader.readLine();
turtle@29
    63
			card = breader.readLine();
turtle@29
    64
		}
turtle@29
    65
		else
turtle@29
    66
		{
turtle@29
    67
			// do nothing
turtle@29
    68
		}
turtle@15
    69
		
turtle@29
    70
		if(turnCase == null || card == null || slot == null)
turtle@15
    71
		{
turtle@15
    72
			endgame = true;
indvdum@94
    73
			return;
turtle@15
    74
		}
indvdum@94
    75
		
indvdum@94
    76
		
turtle@14
    77
	}
turtle@14
    78
	
turtle@14
    79
	private static void writeMove()
turtle@14
    80
    {
indvdum@90
    81
		Batch batch = strategy.move(proponent, opponent);
indvdum@90
    82
		System.out.print(batch);
indvdum@90
    83
		proponent.applyBatch(batch);
turtle@14
    84
    }
turtle@15
    85
	
turtle@78
    86
	public static boolean getAutoMode()
turtle@78
    87
	{
turtle@78
    88
		return automodeapply;
turtle@78
    89
	}
turtle@78
    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
}