|
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 ArrayList<Batch> retArray = new ArrayList<Batch>(); |
|
72 |
|
73 if(!(function instanceof Attack || function instanceof Help)){ |
|
74 throw new ICFPCException(); |
|
75 } |
|
76 |
|
77 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot)); |
|
78 retArray.add(new Batch(OperationType.SLOT_TO_CARD, function, processingSlot)); |
|
79 |
|
80 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); |
|
81 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); |
|
82 |
|
83 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot)); |
|
84 |
|
85 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); |
|
86 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); |
|
87 |
|
88 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot)); |
|
89 |
|
90 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); |
|
91 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); |
|
92 |
|
93 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot)); |
|
94 |
|
95 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); |
|
96 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); |
|
97 |
|
98 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot)); |
|
99 |
|
100 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); |
|
101 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); |
|
102 |
|
103 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot)); |
|
104 |
|
105 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); |
|
106 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); |
|
107 |
|
108 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot)); |
|
109 |
|
110 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); |
|
111 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); |
|
112 |
|
113 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot)); |
|
114 |
|
115 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); |
|
116 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); |
|
117 |
|
118 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot)); |
|
119 |
|
120 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); |
|
121 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); |
|
122 |
|
123 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot)); |
|
124 |
|
125 return retArray; |
|
126 } |
|
127 |
|
128 |
|
129 } |