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