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; akhmetovlz@101: import java.io.File; turtle@14: import java.io.IOException; turtle@14: import java.io.InputStreamReader; turtle@14: indvdum@96: import ru.alphatech.icfpc.cards.Attack; indvdum@96: import ru.alphatech.icfpc.cards.Copy; indvdum@96: import ru.alphatech.icfpc.cards.Dbl; indvdum@96: import ru.alphatech.icfpc.cards.Dec; indvdum@96: import ru.alphatech.icfpc.cards.Get; indvdum@96: import ru.alphatech.icfpc.cards.Help; indvdum@96: import ru.alphatech.icfpc.cards.I; indvdum@96: import ru.alphatech.icfpc.cards.ICard; indvdum@96: import ru.alphatech.icfpc.cards.Inc; indvdum@96: import ru.alphatech.icfpc.cards.K; indvdum@96: import ru.alphatech.icfpc.cards.Put; indvdum@96: import ru.alphatech.icfpc.cards.Revive; indvdum@96: import ru.alphatech.icfpc.cards.S; indvdum@96: import ru.alphatech.icfpc.cards.Succ; indvdum@96: import ru.alphatech.icfpc.cards.Zero; indvdum@96: import ru.alphatech.icfpc.cards.Zombie; indvdum@96: import ru.alphatech.icfpc.game.Batch.OperationType; 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@102: private static int callcount = 0; turtle@102: 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 { indvdum@99: proponent.setMyOpponent(opponent); indvdum@99: opponent.setMyOpponent(proponent); 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@92: public static Slot getRegisterByIndex(int registerIndex){ akhmetovlz@92: return proponent.getSlot( registers[registerIndex] ); akhmetovlz@92: } akhmetovlz@92: akhmetovlz@92: public static int getRegisterSlotNum(int registerIndex ){ akhmetovlz@92: return registers[registerIndex]; 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)); indvdum@96: String sTurnCase = breader.readLine(); indvdum@96: String sCard = null; indvdum@96: String sSlot = null; turtle@14: indvdum@96: OperationType operationType = null; indvdum@96: ICard card = null; indvdum@96: Slot slot = null; indvdum@96: indvdum@96: if("1".equals(sTurnCase)) turtle@29: { indvdum@96: sCard = breader.readLine(); indvdum@96: sSlot = breader.readLine(); indvdum@96: operationType = OperationType.CARD_TO_SLOT; turtle@29: } indvdum@96: else if("2".equals(sTurnCase)) turtle@29: { indvdum@96: sSlot = breader.readLine(); indvdum@96: sCard = breader.readLine(); indvdum@96: operationType = OperationType.SLOT_TO_CARD; turtle@29: } turtle@29: else turtle@29: { turtle@29: // do nothing turtle@29: } turtle@15: indvdum@96: if(sTurnCase == null || sCard == null || sSlot == null) turtle@15: { turtle@15: endgame = true; indvdum@94: return; turtle@15: } indvdum@94: indvdum@96: slot = opponent.getSlot(Integer.parseInt(sSlot)); indvdum@96: for(ICard iCard: new ICard[]{ indvdum@96: new Attack(), indvdum@96: new Copy(), indvdum@96: new Dbl(), indvdum@96: new Dec(), indvdum@96: new Get(), indvdum@96: new Help(), indvdum@96: new I(), indvdum@96: new Inc(), indvdum@96: new K(), indvdum@96: new Put(), indvdum@96: new Revive(), indvdum@96: new S(), indvdum@96: new Succ(), indvdum@96: new Zero(), indvdum@96: new Zombie(), indvdum@96: }){ indvdum@96: if(sCard.equals(iCard.getName())){ indvdum@96: card = iCard; indvdum@96: break; indvdum@96: } indvdum@96: } indvdum@96: Batch batch = new Batch(operationType, card, slot); indvdum@96: opponent.applyBatch(batch); 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@102: public static void resetCallCount() turtle@102: { turtle@102: callcount = 0; turtle@102: } turtle@102: turtle@102: public static int incCallCount() turtle@102: { turtle@102: callcount++; turtle@102: turtle@102: return callcount; turtle@102: } turtle@102: turtle@78: public static boolean getAutoMode() turtle@78: { turtle@78: return automodeapply; turtle@78: } turtle@78: indvdum@106: public static void setAutoMode(boolean b){ indvdum@106: automodeapply = b; indvdum@106: } indvdum@106: 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: }