src/main/java/ru/alphatech/icfpc/game/Run.java
changeset 98 19dba9e387ce
parent 96 8c40512777a1
child 99 60187fe9405d
child 102 cc814352ab43
equal deleted inserted replaced
97:89f13f209302 98:19dba9e387ce
     6 package ru.alphatech.icfpc.game;
     6 package ru.alphatech.icfpc.game;
     7 
     7 
     8 import java.io.BufferedReader;
     8 import java.io.BufferedReader;
     9 import java.io.IOException;
     9 import java.io.IOException;
    10 import java.io.InputStreamReader;
    10 import java.io.InputStreamReader;
    11 import java.util.LinkedList;
       
    12 import java.util.List;
       
    13 
    11 
       
    12 import ru.alphatech.icfpc.cards.Attack;
       
    13 import ru.alphatech.icfpc.cards.Copy;
       
    14 import ru.alphatech.icfpc.cards.Dbl;
       
    15 import ru.alphatech.icfpc.cards.Dec;
       
    16 import ru.alphatech.icfpc.cards.Get;
       
    17 import ru.alphatech.icfpc.cards.Help;
       
    18 import ru.alphatech.icfpc.cards.I;
       
    19 import ru.alphatech.icfpc.cards.ICard;
       
    20 import ru.alphatech.icfpc.cards.Inc;
       
    21 import ru.alphatech.icfpc.cards.K;
       
    22 import ru.alphatech.icfpc.cards.Put;
       
    23 import ru.alphatech.icfpc.cards.Revive;
       
    24 import ru.alphatech.icfpc.cards.S;
       
    25 import ru.alphatech.icfpc.cards.Succ;
       
    26 import ru.alphatech.icfpc.cards.Zero;
       
    27 import ru.alphatech.icfpc.cards.Zombie;
       
    28 import ru.alphatech.icfpc.game.Batch.OperationType;
    14 import ru.alphatech.icfpc.game.strategy.IStrategy;
    29 import ru.alphatech.icfpc.game.strategy.IStrategy;
    15 import ru.alphatech.icfpc.game.strategy.SimplyStrategy;
    30 import ru.alphatech.icfpc.game.strategy.SimplyStrategy;
    16 
    31 
    17 public class Run
    32 public class Run
    18 {
    33 {
       
    34 	private static boolean automodeapply = false;
       
    35 
    19 	private static boolean endgame = false;
    36 	private static boolean endgame = false;
    20 	
    37 	
    21 	private static Player proponent = new Player();
    38 	private static Player proponent = new Player();
    22 	
    39 	
    23 	private static Player opponent = new Player();
    40 	private static Player opponent = new Player();
    24 	
       
    25 	private static LinkedList<Batch> batches = new LinkedList<Batch>();
       
    26 	
    41 	
    27 	private static int registers[] = new int[4];
    42 	private static int registers[] = new int[4];
    28 	
    43 	
    29 	static {
    44 	static {
    30 		registers[0] = 0;
    45 		registers[0] = 0;
    33 		registers[3] = 3;
    48 		registers[3] = 3;
    34 	}
    49 	}
    35 	
    50 	
    36 	private static IStrategy strategy = new SimplyStrategy();
    51 	private static IStrategy strategy = new SimplyStrategy();
    37 	
    52 	
    38 	public static Slot getRegisterByIndex(int registerIdex){
    53 	public static Slot getRegisterByIndex(int registerIndex){
    39 		return proponent.getSlot( registers[registerIdex] );
    54 		return proponent.getSlot( registers[registerIndex] );
    40 	}
    55 	}
    41 	
    56 	
    42 	public static void clearBatcher(){
    57 	public static int getRegisterSlotNum(int registerIndex ){
    43 		batches.removeAll(batches);
    58 		return registers[registerIndex];
    44 	}
       
    45 	
       
    46 	public static void addBatcher(List<Batch> batches){
       
    47 		batches.addAll(batches);
       
    48 	}
    59 	}
    49 	
    60 	
    50 	public static Player getOpponent(){
    61 	public static Player getOpponent(){
    51 		return opponent;
    62 		return opponent;
    52 	}
    63 	}
    56 	}
    67 	}
    57 	
    68 	
    58 	private static void readOpponent() throws IOException
    69 	private static void readOpponent() throws IOException
    59 	{
    70 	{
    60 		BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
    71 		BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
    61 		String turnCase = breader.readLine();
    72 		String sTurnCase = breader.readLine();
    62 		String card = null;
    73 		String sCard = null;
    63 		String slot = null;
    74 		String sSlot = null;
    64 		
    75 		
    65 		if("1".equals(turnCase))
    76 		OperationType operationType = null;
       
    77 		ICard card = null;
       
    78 		Slot slot = null;
       
    79 		
       
    80 		if("1".equals(sTurnCase))
    66 		{
    81 		{
    67 			card = breader.readLine();
    82 			sCard = breader.readLine();
    68 			slot = breader.readLine();
    83 			sSlot = breader.readLine();
       
    84 			operationType = OperationType.CARD_TO_SLOT;
    69 		}
    85 		}
    70 		else if("2".equals(turnCase))
    86 		else if("2".equals(sTurnCase))
    71 		{
    87 		{
    72 			slot = breader.readLine();
    88 			sSlot = breader.readLine();
    73 			card = breader.readLine();
    89 			sCard = breader.readLine();
       
    90 			operationType = OperationType.SLOT_TO_CARD;
    74 		}
    91 		}
    75 		else
    92 		else
    76 		{
    93 		{
    77 			// do nothing
    94 			// do nothing
    78 		}
    95 		}
    79 		
    96 		
    80 		if(turnCase == null || card == null || slot == null)
    97 		if(sTurnCase == null || sCard == null || sSlot == null)
    81 		{
    98 		{
    82 			endgame = true;
    99 			endgame = true;
       
   100 			return;
    83 		}
   101 		}
       
   102 		
       
   103 		slot = opponent.getSlot(Integer.parseInt(sSlot));
       
   104 		for(ICard iCard: new ICard[]{
       
   105 				new Attack(),
       
   106 				new Copy(),
       
   107 				new Dbl(),
       
   108 				new Dec(),
       
   109 				new Get(),
       
   110 				new Help(),
       
   111 				new I(),
       
   112 				new Inc(),
       
   113 				new K(),
       
   114 				new Put(),
       
   115 				new Revive(),
       
   116 				new S(),
       
   117 				new Succ(),
       
   118 				new Zero(),
       
   119 				new Zombie(),
       
   120 				}){
       
   121 			if(sCard.equals(iCard.getName())){
       
   122 				card = iCard;
       
   123 				break;
       
   124 			}
       
   125 		}
       
   126 		Batch batch = new Batch(operationType, card, slot);
       
   127 		opponent.applyBatch(batch);
    84 	}
   128 	}
    85 	
   129 	
    86 	private static void writeMove()
   130 	private static void writeMove()
    87     {
   131     {
    88 		strategy.moving(proponent, opponent, System.out);
   132 		Batch batch = strategy.move(proponent, opponent);
       
   133 		System.out.print(batch);
       
   134 		proponent.applyBatch(batch);
    89     }
   135     }
       
   136 	
       
   137 	public static boolean getAutoMode()
       
   138 	{
       
   139 		return automodeapply;
       
   140 	}
    90 	
   141 	
    91 	public static void main(String[] args) throws IOException
   142 	public static void main(String[] args) throws IOException
    92     {
   143     {
    93 	    String playerNum = args[0];
   144 	    String playerNum = args[0];
    94 
   145