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