src/main/java/ru/alphatech/icfpc/policy/AttackHelpPolicy.java
changeset 70 99a7f4b52678
child 76 5955cb5e5ef3
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/main/java/ru/alphatech/icfpc/policy/AttackHelpPolicy.java	Sun Jun 19 15:09:51 2011 +0400
     1.3 @@ -0,0 +1,129 @@
     1.4 +package ru.alphatech.icfpc.policy;
     1.5 +
     1.6 +import java.util.ArrayList;
     1.7 +
     1.8 +import ru.alphatech.icfpc.cards.Attack;
     1.9 +import ru.alphatech.icfpc.cards.Get;
    1.10 +import ru.alphatech.icfpc.cards.Help;
    1.11 +import ru.alphatech.icfpc.cards.ICard;
    1.12 +import ru.alphatech.icfpc.cards.K;
    1.13 +import ru.alphatech.icfpc.cards.Put;
    1.14 +import ru.alphatech.icfpc.cards.S;
    1.15 +import ru.alphatech.icfpc.cards.Succ;
    1.16 +import ru.alphatech.icfpc.cards.Zero;
    1.17 +import ru.alphatech.icfpc.game.AbstractPolicy;
    1.18 +import ru.alphatech.icfpc.game.Batch;
    1.19 +import ru.alphatech.icfpc.game.ICFPCException;
    1.20 +import ru.alphatech.icfpc.game.Run;
    1.21 +import ru.alphatech.icfpc.game.Slot;
    1.22 +import ru.alphatech.icfpc.game.Batch.OperationType;
    1.23 +
    1.24 +public class AttackHelpPolicy extends AbstractPolicy {
    1.25 +
    1.26 +	private int donorSlotIndex   = -1;
    1.27 +	private int targetSlotIndex  = -1;
    1.28 +	private int pointsSlotIndex  = -1;
    1.29 +	private int processingSlotIndex = -1;
    1.30 +	
    1.31 +	private TYPE type;
    1.32 +	
    1.33 +	public enum TYPE {
    1.34 +		ATTACK,
    1.35 +		HELP
    1.36 +	}
    1.37 +	
    1.38 +	/**
    1.39 +	 * 
    1.40 +	 * @param processingSlot - в какой ячейке проводить
    1.41 +	 * @param donor - от кого забирать хп
    1.42 +	 * @param target - слот который надо атаковать
    1.43 +	 * @param points - количество хп отнимаемое у донора
    1.44 +	 */
    1.45 +	public AttackHelpPolicy(TYPE type, int processingSlot, int donor, int target, int points) {
    1.46 +		this.donorSlotIndex  = donor;
    1.47 +		this.targetSlotIndex = target;
    1.48 +		this.pointsSlotIndex = points;
    1.49 +		this.processingSlotIndex = processingSlot;
    1.50 +		
    1.51 +		this.type = type;
    1.52 +	}
    1.53 +	
    1.54 +	@Override
    1.55 +	public ArrayList<Batch> getBatches() {
    1.56 +		ArrayList<Batch> retArray = new ArrayList<Batch>();
    1.57 +		
    1.58 +		Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex);
    1.59 +		
    1.60 +		numberIntoSlotField(Run.getRegisterByIndex(0), donorSlotIndex);
    1.61 +		numberIntoSlotField(Run.getRegisterByIndex(1), targetSlotIndex);
    1.62 +		numberIntoSlotField(Run.getRegisterByIndex(2), pointsSlotIndex);
    1.63 +		
    1.64 +		retArray.addAll(BcombineForFunctWith3ParamsInRegister(getCard(), processingSlot));
    1.65 +		
    1.66 +		return retArray;
    1.67 +	}
    1.68 +	
    1.69 +	public ICard getCard(){
    1.70 +		return type == TYPE.ATTACK ? new Attack() : new Help();
    1.71 +	}
    1.72 +	
    1.73 +	protected ArrayList<Batch> BcombineForFunctWith3ParamsInRegister(ICard function, Slot processingSlot){
    1.74 +		ArrayList<Batch> retArray = new ArrayList<Batch>();
    1.75 +		
    1.76 +		if(!(function instanceof Attack || function instanceof Help)){
    1.77 +			throw new ICFPCException();
    1.78 +		}
    1.79 +		
    1.80 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
    1.81 +		retArray.add(new Batch(OperationType.SLOT_TO_CARD, function,  processingSlot));
    1.82 +		
    1.83 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    1.84 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
    1.85 +		
    1.86 +		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
    1.87 +
    1.88 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    1.89 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
    1.90 +		
    1.91 +		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
    1.92 +		
    1.93 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    1.94 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
    1.95 +		
    1.96 +		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
    1.97 +
    1.98 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    1.99 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   1.100 +		
   1.101 +		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
   1.102 +		
   1.103 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   1.104 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   1.105 +		
   1.106 +		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
   1.107 +		
   1.108 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   1.109 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   1.110 +		
   1.111 +		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
   1.112 +
   1.113 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   1.114 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   1.115 +		
   1.116 +		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
   1.117 +		
   1.118 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   1.119 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   1.120 +		
   1.121 +		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
   1.122 +		
   1.123 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   1.124 +		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   1.125 +		
   1.126 +		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
   1.127 +		
   1.128 +		return retArray;
   1.129 +	}
   1.130 +
   1.131 +
   1.132 +}