1 package ru.alphatech.icfpc.policy;
3 import java.util.ArrayList;
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;
21 public class AttackHelpPolicy extends AbstractPolicy {
23 private int donorSlotIndex = -1;
24 private int targetSlotIndex = -1;
25 private int pointsSlotIndex = -1;
26 private int processingSlotIndex = -1;
27 private boolean execute = false;
37 * @param type - ATTACK or HELP
38 * @param processingSlot - в какой ячейке проводить
39 * @param donor - от кого забирать хп
40 * @param target - слот который надо атаковать
41 * @param points - количество хп отнимаемое у донора
42 * @param execute - выполнить после завершения либо просто сохранить в слоте.
44 public AttackHelpPolicy(TYPE type, int processingSlot, int donor, int target, int points, boolean execute) {
45 this.donorSlotIndex = donor;
46 this.targetSlotIndex = target;
47 this.pointsSlotIndex = points;
48 this.processingSlotIndex = processingSlot;
49 this.execute = execute;
55 public ArrayList<Batch> getBatches() {
56 ArrayList<Batch> retArray = new ArrayList<Batch>();
58 Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex);
60 retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(0), donorSlotIndex));
61 retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(1), targetSlotIndex));
62 retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(2), pointsSlotIndex));
64 retArray.addAll(BcombineForFunctWith3ParamsInRegister(getCard(), processingSlot));
69 public ICard getCard(){
70 return type == TYPE.ATTACK ? new Attack() : new Help();
73 protected ArrayList<Batch> BcombineForFunctWith3ParamsInRegister(ICard function, Slot processingSlot)
75 ArrayList<Batch> retArray = new ArrayList<Batch>();
77 if(!(function instanceof Attack || function instanceof Help)){
78 throw new ICFPCException();
81 //TODO Абстрагироваться от регистров
83 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
84 retArray.add(new Batch(OperationType.SLOT_TO_CARD, function, processingSlot));
86 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
87 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
89 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
91 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
93 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
94 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
96 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
98 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
99 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
101 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
103 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
105 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
106 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
108 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
110 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
111 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
113 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
115 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
116 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
118 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
121 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));