1 package ru.alphatech.icfpc.policy; |
|
2 |
|
3 import java.util.ArrayList; |
|
4 |
|
5 import ru.alphatech.icfpc.cards.Dec; |
|
6 import ru.alphatech.icfpc.cards.Get; |
|
7 import ru.alphatech.icfpc.cards.ICard; |
|
8 import ru.alphatech.icfpc.cards.Inc; |
|
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.Zero; |
|
13 import ru.alphatech.icfpc.game.AbstractPolicy; |
|
14 import ru.alphatech.icfpc.game.Batch; |
|
15 import ru.alphatech.icfpc.game.IValue; |
|
16 import ru.alphatech.icfpc.game.Run; |
|
17 import ru.alphatech.icfpc.game.Slot; |
|
18 import ru.alphatech.icfpc.game.Value; |
|
19 import ru.alphatech.icfpc.game.Batch.OperationType; |
|
20 |
|
21 public class DecIncPolicy extends AbstractPolicy{ |
|
22 |
|
23 public enum TYPE { |
|
24 DEC, |
|
25 INC |
|
26 } |
|
27 |
|
28 private TYPE type; |
|
29 private int processingSlotIndex = -1; |
|
30 private int targetSlotIndex = -1; |
|
31 |
|
32 |
|
33 public DecIncPolicy(TYPE type, int processingSlot, int target) { |
|
34 this.type = type; |
|
35 this.processingSlotIndex = processingSlot; |
|
36 this.targetSlotIndex = target; |
|
37 } |
|
38 |
|
39 public ICard getCard(){ |
|
40 return type == TYPE.DEC ? new Dec() : new Inc(); |
|
41 } |
|
42 |
|
43 @Override |
|
44 public ArrayList<Batch> getBatches() { |
|
45 ArrayList<Batch> retArray = new ArrayList<Batch>(); |
|
46 |
|
47 retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(0), targetSlotIndex)); |
|
48 |
|
49 Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex); |
|
50 IValue slotValue = processingSlot.getValue(); |
|
51 |
|
52 if(slotValue instanceof Value){ |
|
53 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot)); |
|
54 retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot)); |
|
55 }else{ |
|
56 ICard currentCard = (ICard) slotValue; |
|
57 if(!(currentCard instanceof Dec && type == TYPE.DEC) || |
|
58 !(currentCard instanceof Inc && type == TYPE.INC)) |
|
59 { |
|
60 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot)); |
|
61 retArray.add(new Batch(OperationType.SLOT_TO_CARD, getCard(), processingSlot)); |
|
62 } |
|
63 } |
|
64 |
|
65 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot)); |
|
66 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot)); |
|
67 |
|
68 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot)); |
|
69 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot)); |
|
70 |
|
71 return retArray; |
|
72 } |
|
73 |
|
74 } |
|