src/main/java/ru/alphatech/icfpc/policy/AttackHelpPolicy.java
changeset 120 f8c080bbb572
parent 115 21f9fa7770cc
     1.1 --- a/src/main/java/ru/alphatech/icfpc/policy/AttackHelpPolicy.java	Mon Jun 20 00:49:37 2011 +0400
     1.2 +++ b/src/main/java/ru/alphatech/icfpc/policy/AttackHelpPolicy.java	Mon Jun 20 01:42:04 2011 +0400
     1.3 @@ -24,7 +24,6 @@
     1.4  	private int targetSlotIndex  = -1;
     1.5  	private int pointsSlotIndex  = -1;
     1.6  	private int processingSlotIndex = -1;
     1.7 -	private boolean execute = false;
     1.8  	
     1.9  	private TYPE type;
    1.10  	
    1.11 @@ -34,23 +33,29 @@
    1.12  	}
    1.13  	
    1.14  	/**
    1.15 +	 * Выполнить
    1.16 +	 * 
    1.17  	 * @param type - ATTACK or HELP
    1.18  	 * @param processingSlot - в какой ячейке проводить
    1.19  	 * @param donor - от кого забирать хп
    1.20  	 * @param target - слот который надо атаковать
    1.21  	 * @param points - количество хп отнимаемое у донора
    1.22 -	 * @param execute - выполнить после завершения либо просто сохранить в слоте.
    1.23  	 */
    1.24 -	public AttackHelpPolicy(TYPE type, int processingSlot, int donor, int target, int points, boolean execute) {
    1.25 +	public AttackHelpPolicy(TYPE type, int processingSlot, int donor, int target, int points) {
    1.26  		this.donorSlotIndex  = donor;
    1.27  		this.targetSlotIndex = target;
    1.28  		this.pointsSlotIndex = points;
    1.29 -		this.processingSlotIndex = processingSlot;
    1.30 -		this.execute = execute;
    1.31 +		this.processingSlotIndex = processingSlot; 
    1.32  		
    1.33  		this.type = type;
    1.34  	}
    1.35  	
    1.36 +	protected ArrayList<Batch> registerChangingBatches(Slot processingSlot){
    1.37 +		ArrayList<Batch> retArray = new ArrayList<Batch>();
    1.38 +		retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(2), pointsSlotIndex));
    1.39 +		return retArray;
    1.40 +	}
    1.41 +	
    1.42  	@Override
    1.43  	public ArrayList<Batch> getBatches() {
    1.44  		ArrayList<Batch> retArray = new ArrayList<Batch>();
    1.45 @@ -59,7 +64,8 @@
    1.46  		
    1.47  		retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(0), donorSlotIndex));
    1.48  		retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(1), targetSlotIndex));
    1.49 -		retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(2), pointsSlotIndex));
    1.50 +		
    1.51 +		retArray.addAll(registerChangingBatches(processingSlot));
    1.52  		
    1.53  //		retArray.addAll(BcombineForFunctWith3ParamsInRegister(getCard(), processingSlot));
    1.54  		retArray.addAll(BcombineForFunctWith3ParamsInRegister2(getCard(), processingSlot));
    1.55 @@ -71,6 +77,13 @@
    1.56  		return type == TYPE.ATTACK ? new Attack() : new Help();
    1.57  	}
    1.58  	
    1.59 +	protected int get3thRegisterIndex(){
    1.60 +		return 2;
    1.61 +	}
    1.62 +	
    1.63 +	protected boolean execute(){
    1.64 +		return true;
    1.65 +	}
    1.66  
    1.67  
    1.68  	/**
    1.69 @@ -113,68 +126,11 @@
    1.70  		
    1.71  		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
    1.72  	
    1.73 -		retArray.addAll(correctRegister(2, processingSlot));
    1.74 -		
    1.75 -		if(execute)
    1.76 +		retArray.addAll(correctRegister(get3thRegisterIndex(), processingSlot));
    1.77 +		if(execute())
    1.78  			retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
    1.79  		
    1.80  		return retArray;
    1.81  	}
    1.82  	
    1.83 -	/***
    1.84 -	 * @deprecated
    1.85 -	 * @param function
    1.86 -	 * @param processingSlot
    1.87 -	 * @return
    1.88 -	 */
    1.89 -	protected ArrayList<Batch> BcombineForFunctWith3ParamsInRegister(ICard function, Slot processingSlot)
    1.90 -	{
    1.91 -		ArrayList<Batch> retArray = new ArrayList<Batch>();
    1.92 -		
    1.93 -		if(!(function instanceof Attack || function instanceof Help)){
    1.94 -			throw new ICFPCException();
    1.95 -		}
    1.96 -		
    1.97 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
    1.98 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, function,  processingSlot));
    1.99 -		
   1.100 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   1.101 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   1.102 -		
   1.103 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
   1.104 -		
   1.105 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
   1.106 -		
   1.107 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   1.108 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   1.109 -		
   1.110 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
   1.111 -
   1.112 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   1.113 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   1.114 -		
   1.115 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
   1.116 -		
   1.117 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
   1.118 -		
   1.119 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   1.120 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   1.121 -		
   1.122 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
   1.123 -
   1.124 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   1.125 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   1.126 -		
   1.127 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
   1.128 -		
   1.129 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   1.130 -		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   1.131 -		
   1.132 -		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
   1.133 -		
   1.134 -		if(execute)
   1.135 -			retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
   1.136 -		
   1.137 -		return retArray;
   1.138 -	}
   1.139  }