turtle@13: /*********************************************** turtle@13: * icfpc-2011 turtle@13: * بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِِ turtle@13: * Time: 18.06.2011 11:37:46 turtle@13: ***********************************************/ turtle@13: package ru.alphatech.icfpc.game; turtle@13: turtle@14: import java.io.BufferedReader; turtle@14: import java.io.IOException; turtle@14: import java.io.InputStreamReader; turtle@14: indvdum@55: import ru.alphatech.icfpc.game.strategy.IStrategy; indvdum@55: import ru.alphatech.icfpc.game.strategy.SimplyStrategy; indvdum@55: turtle@13: public class Run turtle@13: { turtle@78: private static boolean automodeapply = false; turtle@78: turtle@15: private static boolean endgame = false; turtle@15: turtle@14: private static Player proponent = new Player(); turtle@14: turtle@14: private static Player opponent = new Player(); turtle@14: akhmetovlz@48: private static int registers[] = new int[4]; akhmetovlz@48: akhmetovlz@48: static { akhmetovlz@48: registers[0] = 0; akhmetovlz@48: registers[1] = 1; akhmetovlz@48: registers[2] = 2; akhmetovlz@48: registers[3] = 3; akhmetovlz@48: } akhmetovlz@48: indvdum@55: private static IStrategy strategy = new SimplyStrategy(); indvdum@55: akhmetovlz@48: public static Slot getRegisterByIndex(int registerIdex){ akhmetovlz@48: return proponent.getSlot( registers[registerIdex] ); akhmetovlz@48: } akhmetovlz@48: akhmetovlz@48: public static Player getOpponent(){ akhmetovlz@48: return opponent; akhmetovlz@48: } akhmetovlz@48: akhmetovlz@48: public static Player getProponent(){ akhmetovlz@48: return proponent; akhmetovlz@31: } akhmetovlz@31: turtle@14: private static void readOpponent() throws IOException turtle@14: { turtle@14: BufferedReader breader = new BufferedReader(new InputStreamReader(System.in)); turtle@29: String turnCase = breader.readLine(); turtle@29: String card = null; turtle@29: String slot = null; turtle@14: turtle@29: if("1".equals(turnCase)) turtle@29: { turtle@29: card = breader.readLine(); turtle@29: slot = breader.readLine(); turtle@29: } turtle@29: else if("2".equals(turnCase)) turtle@29: { turtle@29: slot = breader.readLine(); turtle@29: card = breader.readLine(); turtle@29: } turtle@29: else turtle@29: { turtle@29: // do nothing turtle@29: } turtle@15: turtle@29: if(turnCase == null || card == null || slot == null) turtle@15: { turtle@15: endgame = true; indvdum@94: return; turtle@15: } indvdum@94: indvdum@94: turtle@14: } turtle@14: turtle@14: private static void writeMove() turtle@14: { indvdum@90: Batch batch = strategy.move(proponent, opponent); indvdum@90: System.out.print(batch); indvdum@90: proponent.applyBatch(batch); turtle@14: } turtle@15: turtle@78: public static boolean getAutoMode() turtle@78: { turtle@78: return automodeapply; turtle@78: } turtle@78: turtle@14: public static void main(String[] args) throws IOException turtle@13: { turtle@13: String playerNum = args[0]; turtle@15: turtle@14: if("1".equals(playerNum)) turtle@14: { turtle@14: readOpponent(); turtle@14: } turtle@14: turtle@15: while(!endgame) turtle@15: { turtle@15: writeMove(); turtle@15: readOpponent(); turtle@15: } turtle@13: } turtle@13: }