* merge
authorindvdum
Sun, 19 Jun 2011 17:13:20 +0400
changeset 81da95a7576365
parent 80 fcdce54b2f25
parent 78 7eacf1e21213
child 82 4c6576c03f93
* merge
src/main/java/ru/alphatech/icfpc/game/Run.java
     1.1 --- a/src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java	Sun Jun 19 17:09:51 2011 +0400
     1.2 +++ b/src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java	Sun Jun 19 17:13:20 2011 +0400
     1.3 @@ -91,63 +91,5 @@
     1.4  		return retArray;
     1.5  	}
     1.6  	
     1.7 -	protected ArrayList<Batch> BcombineForFunctWith3ParamsInRegister(ICard function, Slot processingSlot){
     1.8 -		ArrayList<Batch> retArray = new ArrayList<Batch>();
     1.9 -		
    1.10 -		if(!(function instanceof Attack || function instanceof Help)){
    1.11 -			throw new ICFPCException();
    1.12 -		}
    1.13 -		
    1.14 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
    1.15 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, function,  processingSlot));
    1.16 -		
    1.17 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    1.18 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
    1.19 -		
    1.20 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
    1.21 -
    1.22 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    1.23 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
    1.24 -		
    1.25 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
    1.26 -		
    1.27 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    1.28 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
    1.29 -		
    1.30 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
    1.31 -
    1.32 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    1.33 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
    1.34 -		
    1.35 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
    1.36 -		
    1.37 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    1.38 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
    1.39 -		
    1.40 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
    1.41 -		
    1.42 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    1.43 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
    1.44 -		
    1.45 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
    1.46 -
    1.47 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    1.48 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
    1.49 -		
    1.50 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
    1.51 -		
    1.52 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    1.53 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
    1.54 -		
    1.55 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
    1.56 -		
    1.57 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    1.58 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
    1.59 -		
    1.60 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
    1.61 -		
    1.62 -		return retArray;
    1.63 -	}
    1.64 -	
    1.65  	public abstract ArrayList<Batch> getBatches();
    1.66  }
     2.1 --- a/src/main/java/ru/alphatech/icfpc/game/Run.java	Sun Jun 19 17:09:51 2011 +0400
     2.2 +++ b/src/main/java/ru/alphatech/icfpc/game/Run.java	Sun Jun 19 17:13:20 2011 +0400
     2.3 @@ -15,6 +15,8 @@
     2.4  
     2.5  public class Run
     2.6  {
     2.7 +	private static boolean automodeapply = false;
     2.8 +
     2.9  	private static boolean endgame = false;
    2.10  	
    2.11  	private static Player proponent = new Player();
    2.12 @@ -77,6 +79,11 @@
    2.13  		strategy.moving(proponent, opponent, System.out);
    2.14      }
    2.15  	
    2.16 +	public static boolean getAutoMode()
    2.17 +	{
    2.18 +		return automodeapply;
    2.19 +	}
    2.20 +	
    2.21  	public static void main(String[] args) throws IOException
    2.22      {
    2.23  	    String playerNum = args[0];
     3.1 --- a/src/main/java/ru/alphatech/icfpc/policy/AttackHelpPolicy.java	Sun Jun 19 17:09:51 2011 +0400
     3.2 +++ b/src/main/java/ru/alphatech/icfpc/policy/AttackHelpPolicy.java	Sun Jun 19 17:13:20 2011 +0400
     3.3 @@ -67,7 +67,8 @@
     3.4  		return type == TYPE.ATTACK ? new Attack() : new Help();
     3.5  	}
     3.6  	
     3.7 -	protected ArrayList<Batch> BcombineForFunctWith3ParamsInRegister(ICard function, Slot processingSlot){
     3.8 +	protected ArrayList<Batch> BcombineForFunctWith3ParamsInRegister(ICard function, Slot processingSlot)
     3.9 +	{
    3.10  		ArrayList<Batch> retArray = new ArrayList<Batch>();
    3.11  		
    3.12  		if(!(function instanceof Attack || function instanceof Help)){
     4.1 --- a/src/main/java/ru/alphatech/icfpc/policy/CompositionPolicy.java	Sun Jun 19 17:09:51 2011 +0400
     4.2 +++ b/src/main/java/ru/alphatech/icfpc/policy/CompositionPolicy.java	Sun Jun 19 17:13:20 2011 +0400
     4.3 @@ -5,19 +5,19 @@
     4.4  import ru.alphatech.icfpc.game.AbstractPolicy;
     4.5  import ru.alphatech.icfpc.game.Batch;
     4.6  
     4.7 -public class CompositionPolicy extends AbstractPolicy{
     4.8 +public abstract class CompositionPolicy extends AbstractPolicy{
     4.9  	
    4.10  	protected ArrayList<AbstractPolicy> policies = new ArrayList<AbstractPolicy>();
    4.11  
    4.12 -	public void addPolicy(AbstractPolicy policy){
    4.13 +	protected void addPolicy(AbstractPolicy policy){
    4.14  		policies.add(policy);
    4.15  	}
    4.16  	
    4.17 -	public void removePolicy(AbstractPolicy policy){
    4.18 +	protected void removePolicy(AbstractPolicy policy){
    4.19  		policies.remove(policy);
    4.20  	}
    4.21  	
    4.22 -	public AbstractPolicy getPolicy(int index){
    4.23 +	protected AbstractPolicy getPolicy(int index){
    4.24  		return policies.get(index);
    4.25  	}
    4.26  	
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/main/java/ru/alphatech/icfpc/policy/DecIncPolicy.java	Sun Jun 19 17:13:20 2011 +0400
     5.3 @@ -0,0 +1,74 @@
     5.4 +package ru.alphatech.icfpc.policy;
     5.5 +
     5.6 +import java.util.ArrayList;
     5.7 +
     5.8 +import ru.alphatech.icfpc.cards.Dec;
     5.9 +import ru.alphatech.icfpc.cards.Get;
    5.10 +import ru.alphatech.icfpc.cards.ICard;
    5.11 +import ru.alphatech.icfpc.cards.Inc;
    5.12 +import ru.alphatech.icfpc.cards.K;
    5.13 +import ru.alphatech.icfpc.cards.Put;
    5.14 +import ru.alphatech.icfpc.cards.S;
    5.15 +import ru.alphatech.icfpc.cards.Zero;
    5.16 +import ru.alphatech.icfpc.game.AbstractPolicy;
    5.17 +import ru.alphatech.icfpc.game.Batch;
    5.18 +import ru.alphatech.icfpc.game.IValue;
    5.19 +import ru.alphatech.icfpc.game.Run;
    5.20 +import ru.alphatech.icfpc.game.Slot;
    5.21 +import ru.alphatech.icfpc.game.Value;
    5.22 +import ru.alphatech.icfpc.game.Batch.OperationType;
    5.23 +
    5.24 +public class DecIncPolicy extends AbstractPolicy{
    5.25 +	
    5.26 +	public enum TYPE {
    5.27 +		DEC,
    5.28 +		INC
    5.29 +	}
    5.30 +	
    5.31 +	private TYPE type;
    5.32 +	private int processingSlotIndex = -1;
    5.33 +	private int targetSlotIndex = -1;
    5.34 +	
    5.35 +	
    5.36 +	public DecIncPolicy(TYPE type, int processingSlot, int target) {
    5.37 +		this.type = type;
    5.38 +		this.processingSlotIndex = processingSlot;
    5.39 +		this.targetSlotIndex = target;
    5.40 +	}
    5.41 +	
    5.42 +	public ICard getCard(){
    5.43 +		return type == TYPE.DEC ? new Dec() : new Inc();
    5.44 +	}
    5.45 +
    5.46 +	@Override
    5.47 +	public ArrayList<Batch> getBatches() {
    5.48 +		ArrayList<Batch> retArray = new ArrayList<Batch>();
    5.49 +		
    5.50 +		retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(0), targetSlotIndex));
    5.51 +		
    5.52 +		Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex);
    5.53 +		IValue slotValue = processingSlot.getValue();
    5.54 +		
    5.55 +		if(slotValue instanceof Value){
    5.56 +			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
    5.57 +			retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot));
    5.58 +		}else{
    5.59 +			ICard currentCard = (ICard) slotValue;
    5.60 +			if(!(currentCard instanceof Dec && type == TYPE.DEC) || 
    5.61 +			   !(currentCard instanceof Inc && type == TYPE.INC))
    5.62 +			{
    5.63 +				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
    5.64 +				retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot));
    5.65 +			}
    5.66 +		}
    5.67 +		
    5.68 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    5.69 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
    5.70 +		
    5.71 +		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
    5.72 +		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
    5.73 +		
    5.74 +		return retArray;
    5.75 +	}
    5.76 +	
    5.77 +}