1 package ru.alphatech.icfpc.game; |
1 package ru.alphatech.icfpc.game; |
2 |
2 |
3 import java.util.ArrayList; |
3 import java.util.ArrayList; |
|
4 import java.util.Collections; |
|
5 import java.util.List; |
4 |
6 |
5 import ru.alphatech.icfpc.cards.Attack; |
7 import ru.alphatech.icfpc.cards.Attack; |
6 import ru.alphatech.icfpc.cards.Dbl; |
8 import ru.alphatech.icfpc.cards.Dbl; |
7 import ru.alphatech.icfpc.cards.Get; |
9 import ru.alphatech.icfpc.cards.Get; |
8 import ru.alphatech.icfpc.cards.Help; |
10 import ru.alphatech.icfpc.cards.Help; |
72 begin ++; |
74 begin ++; |
73 } |
75 } |
74 return retArray; |
76 return retArray; |
75 } |
77 } |
76 |
78 |
77 protected ArrayList<Batch> smartAlg(int begin, int end, Slot targetSlot){ |
79 protected static List<Batch> smartAlg(int begin, int end, Slot targetSlot){ |
78 ArrayList<Batch> retArray = new ArrayList<Batch>(); |
80 ArrayList<Batch> retArray = new ArrayList<Batch>(); |
79 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); |
81 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); |
80 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot)); |
82 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot)); |
81 while(end >= 2){ |
83 |
82 int d = end % 2; |
84 List<Batch> list1 = buildNumberOperations(0, end, targetSlot); |
83 if( d == 0 ) { |
85 List<Batch> list2 = buildNumberOperations(begin, end, targetSlot); |
84 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot)); |
86 if (list1.size() <= list2.size()) |
85 } else { |
87 { |
86 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot)); |
88 Collections.reverse(list1); |
87 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot)); |
89 retArray.addAll(list1); |
88 } |
90 } |
89 end = end / 2; |
91 else |
|
92 { |
|
93 Collections.reverse(list2); |
|
94 retArray.addAll(list2); |
90 } |
95 } |
91 return retArray; |
96 return retArray; |
92 } |
97 } |
93 |
98 |
|
99 protected static List<Batch> buildNumberOperations(int begin, int end, Slot targetSlot){ |
|
100 List<Batch> list = new ArrayList<Batch>(); |
|
101 |
|
102 while(end >= 2){ |
|
103 int d = end % 2; |
|
104 if (begin > 0 && 2*begin > end) |
|
105 { |
|
106 for (int i = 0; i < end - begin; i++) |
|
107 { |
|
108 list.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot)); |
|
109 } |
|
110 break; |
|
111 } |
|
112 if( d == 0 ) { |
|
113 list.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot)); |
|
114 end = end / 2; |
|
115 } else { |
|
116 list.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot)); |
|
117 list.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot)); |
|
118 end = (end-1) / 2; |
|
119 } |
|
120 } |
|
121 return list; |
|
122 } |
|
123 |
94 public abstract ArrayList<Batch> getBatches(); |
124 public abstract ArrayList<Batch> getBatches(); |
|
125 |
|
126 public static void main(String[] args) |
|
127 { |
|
128 Slot slot = new Slot(1); |
|
129 List<Batch> list = smartAlg(5, 12, slot); |
|
130 System.out.println(list.toArray().toString()); |
|
131 } |
95 } |
132 } |