3 import java.util.ArrayList; |
3 import java.util.ArrayList; |
4 |
4 |
5 import ru.alphatech.icfpc.cards.Dbl; |
5 import ru.alphatech.icfpc.cards.Dbl; |
6 import ru.alphatech.icfpc.cards.ICard; |
6 import ru.alphatech.icfpc.cards.ICard; |
7 import ru.alphatech.icfpc.cards.Put; |
7 import ru.alphatech.icfpc.cards.Put; |
|
8 import ru.alphatech.icfpc.cards.Succ; |
8 import ru.alphatech.icfpc.cards.Zero; |
9 import ru.alphatech.icfpc.cards.Zero; |
9 import ru.alphatech.icfpc.game.Batch; |
10 import ru.alphatech.icfpc.game.Batch; |
10 import ru.alphatech.icfpc.game.IValue; |
11 import ru.alphatech.icfpc.game.IValue; |
11 import ru.alphatech.icfpc.game.Player; |
12 import ru.alphatech.icfpc.game.Player; |
12 import ru.alphatech.icfpc.game.Slot; |
13 import ru.alphatech.icfpc.game.Slot; |
13 import ru.alphatech.icfpc.game.Value; |
14 import ru.alphatech.icfpc.game.Value; |
14 import ru.alphatech.icfpc.game.Batch.OperationType; |
15 import ru.alphatech.icfpc.game.Batch.OperationType; |
15 |
16 |
|
17 /** |
|
18 * |
|
19 * TODO |
|
20 * |
|
21 * @author akhmetovlz |
|
22 * |
|
23 */ |
16 public abstract class AbstractPolicy { |
24 public abstract class AbstractPolicy { |
17 |
25 |
18 protected Player player = null; |
26 protected Player player = null; |
19 |
27 |
20 protected ArrayList<Batch> batches = new ArrayList<Batch>(); |
28 protected ArrayList<Batch> batches = new ArrayList<Batch>(); |
21 |
29 |
22 public AbstractPolicy(Player player){ |
30 public AbstractPolicy(Player player){ |
23 this.player = player; |
31 this.player = player; |
24 } |
32 } |
25 |
33 |
26 public void setRegister0( int num ){ |
34 public void setRegister(int registerIndex, int num ){ |
27 |
35 if( registerIndex < 4) { |
|
36 Slot registerSlot = player.getRegisterByIndex(registerIndex); |
|
37 batches.addAll( numberIntoSlotField( registerSlot, num ) ); |
|
38 } |
28 } |
39 } |
29 |
40 |
30 public void setRegister1( int num ){ |
41 protected ArrayList<Batch> numberIntoSlotField(Slot targetSlot, int number) |
31 |
|
32 } |
|
33 |
|
34 public void setRegister2( int num ){ |
|
35 |
|
36 } |
|
37 |
|
38 protected ArrayList<Batch> numberIntoSlotField(int slot, int number) |
|
39 { |
42 { |
40 ArrayList<Batch> retArray = new ArrayList<Batch>(); |
43 ArrayList<Batch> retArray = new ArrayList<Batch>(); |
41 |
44 |
42 Slot targetSlot = player.getSlot(slot); |
|
43 IValue targetValue = targetSlot.getValue(); |
45 IValue targetValue = targetSlot.getValue(); |
44 |
46 |
45 if(targetValue instanceof ICard){ |
47 if(targetValue instanceof ICard){ |
46 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); |
48 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); |
47 } |
49 } |
48 |
50 |
49 Value numTargetValue = (Value) targetValue; |
51 Value numTargetValue = (Value) targetValue; |
50 if( numTargetValue.getValue() == number ){ |
52 if( numTargetValue.getValue() == number ){ |
51 return retArray; |
53 return retArray; |
52 }else |
54 }else |
53 if( numTargetValue.getValue() < number ){ |
55 if( numTargetValue.getValue() > number ){ |
54 int buffValue = numTargetValue.getValue(); |
|
55 while( buffValue*2 < number){ |
|
56 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); |
|
57 } |
|
58 while( buffValue != number){ |
|
59 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); |
|
60 } |
|
61 }else{ |
|
62 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); |
56 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); |
63 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot)); |
57 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot)); |
64 int buffValue = numTargetValue.getValue(); |
58 stupidAlg(0, number, targetSlot); |
65 while( buffValue*2 < number){ |
59 }else{ |
66 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); |
60 stupidAlg(numTargetValue.getValue(), number, targetSlot); |
67 } |
|
68 while( buffValue != number){ |
|
69 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); |
|
70 } |
|
71 } |
61 } |
72 |
62 |
73 return retArray; |
63 return retArray; |
74 |
|
75 } |
64 } |
76 |
65 |
|
66 |
|
67 protected ArrayList<Batch> stupidAlg(int begin, int end, Slot targetSlot){ |
|
68 ArrayList<Batch> retArray = new ArrayList<Batch>(); |
|
69 while( begin*2 < end){ |
|
70 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); |
|
71 begin *= 2; |
|
72 } |
|
73 while( begin != end){ |
|
74 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot)); |
|
75 begin ++; |
|
76 } |
|
77 return retArray; |
|
78 } |
|
79 |
|
80 protected ArrayList<Batch> smartAlg(int begin, int end, Slot targetSlot){ |
|
81 ArrayList<Batch> retArray = new ArrayList<Batch>(); |
|
82 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); |
|
83 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot)); |
|
84 while(end >= 2){ |
|
85 int d = end % 2; |
|
86 if( d == 0 ) { |
|
87 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot)); |
|
88 } else { |
|
89 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot)); |
|
90 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot)); |
|
91 } |
|
92 end = end / 2; |
|
93 } |
|
94 return retArray; |
|
95 } |
|
96 |
|
97 public abstract ArrayList<Batch> getBatches(); |
77 } |
98 } |