src/main/java/ru/alphatech/icfpc/game/Run.java
author akhmetovlz
Sun, 19 Jun 2011 17:45:47 +0400
changeset 92 2e69298ad664
parent 82 4c6576c03f93
child 93 901ceef564fd
permissions -rw-r--r--
(no commit message)
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@92
    36
	public static Slot getRegisterByIndex(int registerIndex){
akhmetovlz@92
    37
		return proponent.getSlot( registers[registerIndex] );
akhmetovlz@92
    38
	}
akhmetovlz@92
    39
	
akhmetovlz@92
    40
	public static int getRegisterSlotNum(int registerIndex ){
akhmetovlz@92
    41
		return registers[registerIndex];
akhmetovlz@48
    42
	}
akhmetovlz@48
    43
	
akhmetovlz@48
    44
	public static Player getOpponent(){
akhmetovlz@48
    45
		return opponent;
akhmetovlz@48
    46
	}
akhmetovlz@48
    47
	
akhmetovlz@48
    48
	public static Player getProponent(){
akhmetovlz@48
    49
		return proponent;
akhmetovlz@31
    50
	}
akhmetovlz@31
    51
	
turtle@14
    52
	private static void readOpponent() throws IOException
turtle@14
    53
	{
turtle@14
    54
		BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
turtle@29
    55
		String turnCase = breader.readLine();
turtle@29
    56
		String card = null;
turtle@29
    57
		String slot = null;
turtle@14
    58
		
turtle@29
    59
		if("1".equals(turnCase))
turtle@29
    60
		{
turtle@29
    61
			card = breader.readLine();
turtle@29
    62
			slot = breader.readLine();
turtle@29
    63
		}
turtle@29
    64
		else if("2".equals(turnCase))
turtle@29
    65
		{
turtle@29
    66
			slot = breader.readLine();
turtle@29
    67
			card = breader.readLine();
turtle@29
    68
		}
turtle@29
    69
		else
turtle@29
    70
		{
turtle@29
    71
			// do nothing
turtle@29
    72
		}
turtle@15
    73
		
turtle@29
    74
		if(turnCase == null || card == null || slot == null)
turtle@15
    75
		{
turtle@15
    76
			endgame = true;
turtle@15
    77
		}
turtle@14
    78
	}
turtle@14
    79
	
turtle@14
    80
	private static void writeMove()
turtle@14
    81
    {
indvdum@55
    82
		strategy.moving(proponent, opponent, System.out);
turtle@14
    83
    }
turtle@15
    84
	
turtle@78
    85
	public static boolean getAutoMode()
turtle@78
    86
	{
turtle@78
    87
		return automodeapply;
turtle@78
    88
	}
turtle@78
    89
	
turtle@14
    90
	public static void main(String[] args) throws IOException
turtle@13
    91
    {
turtle@13
    92
	    String playerNum = args[0];
turtle@15
    93
turtle@14
    94
	    if("1".equals(playerNum))
turtle@14
    95
	    {
turtle@14
    96
	    	readOpponent();
turtle@14
    97
	    }
turtle@14
    98
	    
turtle@15
    99
	    while(!endgame)
turtle@15
   100
	    {
turtle@15
   101
		    writeMove();
turtle@15
   102
		    readOpponent();
turtle@15
   103
	    }
turtle@13
   104
    }
turtle@13
   105
}