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