src/main/java/ru/alphatech/icfpc/policy/AttackHelpPolicy.java
author akhmetovlz
Sun, 19 Jun 2011 16:52:20 +0400
changeset 76 5955cb5e5ef3
parent 70 99a7f4b52678
child 101 4bb458c3548e
permissions -rw-r--r--
policies
     1 package ru.alphatech.icfpc.policy;
     2 
     3 import java.util.ArrayList;
     4 
     5 import ru.alphatech.icfpc.cards.Attack;
     6 import ru.alphatech.icfpc.cards.Get;
     7 import ru.alphatech.icfpc.cards.Help;
     8 import ru.alphatech.icfpc.cards.ICard;
     9 import ru.alphatech.icfpc.cards.K;
    10 import ru.alphatech.icfpc.cards.Put;
    11 import ru.alphatech.icfpc.cards.S;
    12 import ru.alphatech.icfpc.cards.Succ;
    13 import ru.alphatech.icfpc.cards.Zero;
    14 import ru.alphatech.icfpc.game.AbstractPolicy;
    15 import ru.alphatech.icfpc.game.Batch;
    16 import ru.alphatech.icfpc.game.ICFPCException;
    17 import ru.alphatech.icfpc.game.Run;
    18 import ru.alphatech.icfpc.game.Slot;
    19 import ru.alphatech.icfpc.game.Batch.OperationType;
    20 
    21 public class AttackHelpPolicy extends AbstractPolicy {
    22 
    23 	private int donorSlotIndex   = -1;
    24 	private int targetSlotIndex  = -1;
    25 	private int pointsSlotIndex  = -1;
    26 	private int processingSlotIndex = -1;
    27 	
    28 	private TYPE type;
    29 	
    30 	public enum TYPE {
    31 		ATTACK,
    32 		HELP
    33 	}
    34 	
    35 	/**
    36 	 * 
    37 	 * @param processingSlot - в какой ячейке проводить
    38 	 * @param donor - от кого забирать хп
    39 	 * @param target - слот который надо атаковать
    40 	 * @param points - количество хп отнимаемое у донора
    41 	 */
    42 	public AttackHelpPolicy(TYPE type, int processingSlot, int donor, int target, int points) {
    43 		this.donorSlotIndex  = donor;
    44 		this.targetSlotIndex = target;
    45 		this.pointsSlotIndex = points;
    46 		this.processingSlotIndex = processingSlot;
    47 		
    48 		this.type = type;
    49 	}
    50 	
    51 	@Override
    52 	public ArrayList<Batch> getBatches() {
    53 		ArrayList<Batch> retArray = new ArrayList<Batch>();
    54 		
    55 		Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex);
    56 		
    57 		numberIntoSlotField(Run.getRegisterByIndex(0), donorSlotIndex);
    58 		numberIntoSlotField(Run.getRegisterByIndex(1), targetSlotIndex);
    59 		numberIntoSlotField(Run.getRegisterByIndex(2), pointsSlotIndex);
    60 		
    61 		retArray.addAll(BcombineForFunctWith3ParamsInRegister(getCard(), processingSlot));
    62 		
    63 		return retArray;
    64 	}
    65 	
    66 	public ICard getCard(){
    67 		return type == TYPE.ATTACK ? new Attack() : new Help();
    68 	}
    69 	
    70 	protected ArrayList<Batch> BcombineForFunctWith3ParamsInRegister(ICard function, Slot processingSlot)
    71 	{
    72 		ArrayList<Batch> retArray = new ArrayList<Batch>();
    73 		
    74 		if(!(function instanceof Attack || function instanceof Help)){
    75 			throw new ICFPCException();
    76 		}
    77 		
    78 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
    79 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, function,  processingSlot));
    80 		
    81 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    82 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
    83 		
    84 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
    85 
    86 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    87 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
    88 		
    89 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
    90 		
    91 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    92 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
    93 		
    94 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
    95 
    96 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
    97 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
    98 		
    99 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
   100 		
   101 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   102 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   103 		
   104 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
   105 		
   106 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   107 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   108 		
   109 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
   110 
   111 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   112 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   113 		
   114 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
   115 		
   116 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   117 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   118 		
   119 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
   120 		
   121 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   122 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   123 		
   124 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
   125 		
   126 		return retArray;
   127 	}
   128 
   129 
   130 }