1.1 --- a/src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java Sun Jun 19 17:45:47 2011 +0400
1.2 +++ b/src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java Sun Jun 19 17:46:07 2011 +0400
1.3 @@ -1,6 +1,8 @@
1.4 package ru.alphatech.icfpc.game;
1.5
1.6 import java.util.ArrayList;
1.7 +import java.util.Collections;
1.8 +import java.util.List;
1.9
1.10 import ru.alphatech.icfpc.cards.Attack;
1.11 import ru.alphatech.icfpc.cards.Dbl;
1.12 @@ -74,22 +76,57 @@
1.13 return retArray;
1.14 }
1.15
1.16 - protected ArrayList<Batch> smartAlg(int begin, int end, Slot targetSlot){
1.17 + protected static List<Batch> smartAlg(int begin, int end, Slot targetSlot){
1.18 ArrayList<Batch> retArray = new ArrayList<Batch>();
1.19 retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
1.20 retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
1.21 - while(end >= 2){
1.22 - int d = end % 2;
1.23 - if( d == 0 ) {
1.24 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
1.25 - } else {
1.26 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
1.27 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
1.28 - }
1.29 - end = end / 2;
1.30 +
1.31 + List<Batch> list1 = buildNumberOperations(0, end, targetSlot);
1.32 + List<Batch> list2 = buildNumberOperations(begin, end, targetSlot);
1.33 + if (list1.size() <= list2.size())
1.34 + {
1.35 + Collections.reverse(list1);
1.36 + retArray.addAll(list1);
1.37 + }
1.38 + else
1.39 + {
1.40 + Collections.reverse(list2);
1.41 + retArray.addAll(list2);
1.42 }
1.43 return retArray;
1.44 }
1.45
1.46 + protected static List<Batch> buildNumberOperations(int begin, int end, Slot targetSlot){
1.47 + List<Batch> list = new ArrayList<Batch>();
1.48 +
1.49 + while(end >= 2){
1.50 + int d = end % 2;
1.51 + if (begin > 0 && 2*begin > end)
1.52 + {
1.53 + for (int i = 0; i < end - begin; i++)
1.54 + {
1.55 + list.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
1.56 + }
1.57 + break;
1.58 + }
1.59 + if( d == 0 ) {
1.60 + list.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
1.61 + end = end / 2;
1.62 + } else {
1.63 + list.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
1.64 + list.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
1.65 + end = (end-1) / 2;
1.66 + }
1.67 + }
1.68 + return list;
1.69 + }
1.70 +
1.71 public abstract ArrayList<Batch> getBatches();
1.72 +
1.73 + public static void main(String[] args)
1.74 + {
1.75 + Slot slot = new Slot(1);
1.76 + List<Batch> list = smartAlg(5, 12, slot);
1.77 + System.out.println(list.toArray().toString());
1.78 + }
1.79 }
2.1 --- a/src/main/java/ru/alphatech/icfpc/game/Player.java Sun Jun 19 17:45:47 2011 +0400
2.2 +++ b/src/main/java/ru/alphatech/icfpc/game/Player.java Sun Jun 19 17:46:07 2011 +0400
2.3 @@ -20,17 +20,12 @@
2.4 return slots[i];
2.5 }
2.6
2.7 - public void applyCardToSlot(ICard card, Slot slot){
2.8 - throw new RuntimeException("Not impilemented yet.");
2.9 - }
2.10 -
2.11 - public void applySlotToCard(Slot slot, ICard card){
2.12 - throw new RuntimeException("Not impilemented yet.");
2.13 - }
2.14 -
2.15 public PlayerStatistic getStatistic(){
2.16 throw new RuntimeException("Not impilemented yet.");
2.17 }
2.18
2.19 + public void applyBatch(Batch batch){
2.20 + throw new RuntimeException("Not impilemented yet.");
2.21 + }
2.22
2.23 }
3.1 --- a/src/main/java/ru/alphatech/icfpc/game/Run.java Sun Jun 19 17:45:47 2011 +0400
3.2 +++ b/src/main/java/ru/alphatech/icfpc/game/Run.java Sun Jun 19 17:46:07 2011 +0400
3.3 @@ -79,7 +79,9 @@
3.4
3.5 private static void writeMove()
3.6 {
3.7 - strategy.moving(proponent, opponent, System.out);
3.8 + Batch batch = strategy.move(proponent, opponent);
3.9 + System.out.print(batch);
3.10 + proponent.applyBatch(batch);
3.11 }
3.12
3.13 public static boolean getAutoMode()
4.1 --- a/src/main/java/ru/alphatech/icfpc/game/strategy/IStrategy.java Sun Jun 19 17:45:47 2011 +0400
4.2 +++ b/src/main/java/ru/alphatech/icfpc/game/strategy/IStrategy.java Sun Jun 19 17:46:07 2011 +0400
4.3 @@ -1,7 +1,6 @@
4.4 package ru.alphatech.icfpc.game.strategy;
4.5
4.6 -import java.io.PrintStream;
4.7 -
4.8 +import ru.alphatech.icfpc.game.Batch;
4.9 import ru.alphatech.icfpc.game.Player;
4.10
4.11 /**
4.12 @@ -10,5 +9,5 @@
4.13 *
4.14 */
4.15 public interface IStrategy {
4.16 - public void moving(Player proponent, Player opponent, PrintStream out);
4.17 + public Batch move(Player proponent, Player opponent);
4.18 }
5.1 --- a/src/main/java/ru/alphatech/icfpc/game/strategy/OtherStrategy.java Sun Jun 19 17:45:47 2011 +0400
5.2 +++ b/src/main/java/ru/alphatech/icfpc/game/strategy/OtherStrategy.java Sun Jun 19 17:46:07 2011 +0400
5.3 @@ -21,8 +21,8 @@
5.4 }
5.5
5.6 @Override
5.7 - public void moving(Player proponent, Player opponent, PrintStream out) {
5.8 - out.print(batches.poll());
5.9 + public Batch move(Player proponent, Player opponent) {
5.10 + return batches.poll();
5.11 }
5.12
5.13 }
6.1 --- a/src/main/java/ru/alphatech/icfpc/game/strategy/SimplyStrategy.java Sun Jun 19 17:45:47 2011 +0400
6.2 +++ b/src/main/java/ru/alphatech/icfpc/game/strategy/SimplyStrategy.java Sun Jun 19 17:46:07 2011 +0400
6.3 @@ -1,11 +1,9 @@
6.4 package ru.alphatech.icfpc.game.strategy;
6.5
6.6 -import java.io.PrintStream;
6.7 -
6.8 +import static ru.alphatech.icfpc.game.Batch.OperationType.CARD_TO_SLOT;
6.9 import ru.alphatech.icfpc.cards.I;
6.10 import ru.alphatech.icfpc.game.Batch;
6.11 import ru.alphatech.icfpc.game.Player;
6.12 -import static ru.alphatech.icfpc.game.Batch.OperationType.*;
6.13
6.14 /**
6.15 * @author indvdum
6.16 @@ -15,9 +13,9 @@
6.17 public class SimplyStrategy implements IStrategy {
6.18
6.19 @Override
6.20 - public void moving(Player proponent, Player opponent, PrintStream out) {
6.21 + public Batch move(Player proponent, Player opponent) {
6.22 Batch batch = new Batch(CARD_TO_SLOT, new I(), opponent.getSlot(0));
6.23 - out.print(batch);
6.24 + return batch;
6.25 }
6.26
6.27 }