1.1 --- a/src/main/java/ru/alphatech/icfpc/cards/Get.java Sun Jun 19 13:37:56 2011 +0400
1.2 +++ b/src/main/java/ru/alphatech/icfpc/cards/Get.java Sun Jun 19 13:38:48 2011 +0400
1.3 @@ -1,5 +1,6 @@
1.4 package ru.alphatech.icfpc.cards;
1.5
1.6 +import ru.alphatech.icfpc.game.ICFPCException;
1.7 import ru.alphatech.icfpc.game.IValue;
1.8 import ru.alphatech.icfpc.game.Player;
1.9 import ru.alphatech.icfpc.game.Value;
1.10 @@ -11,11 +12,20 @@
1.11 {
1.12 if (value.getClass().equals(Value.class))
1.13 {
1.14 - return proponent.getSlot(((Value)value).getValue()).getValue();
1.15 + int i = ((Value)value).getValue();
1.16 +
1.17 + if(i >= 0 && i <= 255)
1.18 + {
1.19 + return proponent.getSlot(i).getValue();
1.20 + }
1.21 + else
1.22 + {
1.23 + throw new ICFPCException();
1.24 + }
1.25 }
1.26 else
1.27 {
1.28 - return new Value(-100);
1.29 + throw new ICFPCException();
1.30 }
1.31 }
1.32
2.1 --- a/src/main/java/ru/alphatech/icfpc/cards/Put.java Sun Jun 19 13:37:56 2011 +0400
2.2 +++ b/src/main/java/ru/alphatech/icfpc/cards/Put.java Sun Jun 19 13:38:48 2011 +0400
2.3 @@ -13,7 +13,7 @@
2.4 @Override
2.5 public IValue returnValue(IValue value, Player proponent, Player opponent)
2.6 {
2.7 - return value;
2.8 + return new I();
2.9 }
2.10 };
2.11 }
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java Sun Jun 19 13:38:48 2011 +0400
3.3 @@ -0,0 +1,90 @@
3.4 +package ru.alphatech.icfpc.game;
3.5 +
3.6 +import java.util.ArrayList;
3.7 +
3.8 +import ru.alphatech.icfpc.cards.Dbl;
3.9 +import ru.alphatech.icfpc.cards.ICard;
3.10 +import ru.alphatech.icfpc.cards.Put;
3.11 +import ru.alphatech.icfpc.cards.Succ;
3.12 +import ru.alphatech.icfpc.cards.Zero;
3.13 +import ru.alphatech.icfpc.game.Batch.OperationType;
3.14 +
3.15 +/**
3.16 + *
3.17 + * TODO
3.18 + *
3.19 + * @author akhmetovlz
3.20 + *
3.21 + */
3.22 +public abstract class AbstractPolicy {
3.23 +
3.24 + protected ArrayList<Batch> batches = new ArrayList<Batch>();
3.25 +
3.26 + public AbstractPolicy(){
3.27 + }
3.28 +
3.29 + public void setRegister(int registerIndex, int num ){
3.30 + if( registerIndex < 4) {
3.31 + Slot registerSlot = Run.getRegisterByIndex(registerIndex);
3.32 + batches.addAll( numberIntoSlotField( registerSlot, num ) );
3.33 + }
3.34 + }
3.35 +
3.36 + protected ArrayList<Batch> numberIntoSlotField(Slot targetSlot, int number)
3.37 + {
3.38 + ArrayList<Batch> retArray = new ArrayList<Batch>();
3.39 +
3.40 + IValue targetValue = targetSlot.getValue();
3.41 +
3.42 + if(targetValue instanceof ICard){
3.43 + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
3.44 + }
3.45 +
3.46 + Value numTargetValue = (Value) targetValue;
3.47 + if( numTargetValue.getValue() == number ){
3.48 + return retArray;
3.49 + }else
3.50 + if( numTargetValue.getValue() > number ){
3.51 + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
3.52 + retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
3.53 + stupidAlg(0, number, targetSlot);
3.54 + }else{
3.55 + stupidAlg(numTargetValue.getValue(), number, targetSlot);
3.56 + }
3.57 +
3.58 + return retArray;
3.59 + }
3.60 +
3.61 +
3.62 + protected ArrayList<Batch> stupidAlg(int begin, int end, Slot targetSlot){
3.63 + ArrayList<Batch> retArray = new ArrayList<Batch>();
3.64 + while( begin*2 < end){
3.65 + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
3.66 + begin *= 2;
3.67 + }
3.68 + while( begin != end){
3.69 + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
3.70 + begin ++;
3.71 + }
3.72 + return retArray;
3.73 + }
3.74 +
3.75 + protected ArrayList<Batch> smartAlg(int begin, int end, Slot targetSlot){
3.76 + ArrayList<Batch> retArray = new ArrayList<Batch>();
3.77 + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
3.78 + retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
3.79 + while(end >= 2){
3.80 + int d = end % 2;
3.81 + if( d == 0 ) {
3.82 + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
3.83 + } else {
3.84 + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
3.85 + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
3.86 + }
3.87 + end = end / 2;
3.88 + }
3.89 + return retArray;
3.90 + }
3.91 +
3.92 + public abstract ArrayList<Batch> getBatches();
3.93 +}
4.1 --- a/src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java Sun Jun 19 13:37:56 2011 +0400
4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
4.3 @@ -1,96 +0,0 @@
4.4 -package ru.alphatech.icfpc.policy;
4.5 -
4.6 -import java.util.ArrayList;
4.7 -
4.8 -import ru.alphatech.icfpc.cards.Dbl;
4.9 -import ru.alphatech.icfpc.cards.ICard;
4.10 -import ru.alphatech.icfpc.cards.Put;
4.11 -import ru.alphatech.icfpc.cards.Succ;
4.12 -import ru.alphatech.icfpc.cards.Zero;
4.13 -import ru.alphatech.icfpc.game.Batch;
4.14 -import ru.alphatech.icfpc.game.IValue;
4.15 -import ru.alphatech.icfpc.game.Player;
4.16 -import ru.alphatech.icfpc.game.Run;
4.17 -import ru.alphatech.icfpc.game.Slot;
4.18 -import ru.alphatech.icfpc.game.Value;
4.19 -import ru.alphatech.icfpc.game.Batch.OperationType;
4.20 -
4.21 -/**
4.22 - *
4.23 - * TODO
4.24 - *
4.25 - * @author akhmetovlz
4.26 - *
4.27 - */
4.28 -public abstract class AbstractPolicy {
4.29 -
4.30 - protected ArrayList<Batch> batches = new ArrayList<Batch>();
4.31 -
4.32 - public AbstractPolicy(){
4.33 - }
4.34 -
4.35 - public void setRegister(int registerIndex, int num ){
4.36 - if( registerIndex < 4) {
4.37 - Slot registerSlot = Run.getRegisterByIndex(registerIndex);
4.38 - batches.addAll( numberIntoSlotField( registerSlot, num ) );
4.39 - }
4.40 - }
4.41 -
4.42 - protected ArrayList<Batch> numberIntoSlotField(Slot targetSlot, int number)
4.43 - {
4.44 - ArrayList<Batch> retArray = new ArrayList<Batch>();
4.45 -
4.46 - IValue targetValue = targetSlot.getValue();
4.47 -
4.48 - if(targetValue instanceof ICard){
4.49 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
4.50 - }
4.51 -
4.52 - Value numTargetValue = (Value) targetValue;
4.53 - if( numTargetValue.getValue() == number ){
4.54 - return retArray;
4.55 - }else
4.56 - if( numTargetValue.getValue() > number ){
4.57 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
4.58 - retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
4.59 - stupidAlg(0, number, targetSlot);
4.60 - }else{
4.61 - stupidAlg(numTargetValue.getValue(), number, targetSlot);
4.62 - }
4.63 -
4.64 - return retArray;
4.65 - }
4.66 -
4.67 -
4.68 - protected ArrayList<Batch> stupidAlg(int begin, int end, Slot targetSlot){
4.69 - ArrayList<Batch> retArray = new ArrayList<Batch>();
4.70 - while( begin*2 < end){
4.71 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot));
4.72 - begin *= 2;
4.73 - }
4.74 - while( begin != end){
4.75 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
4.76 - begin ++;
4.77 - }
4.78 - return retArray;
4.79 - }
4.80 -
4.81 - protected ArrayList<Batch> smartAlg(int begin, int end, Slot targetSlot){
4.82 - ArrayList<Batch> retArray = new ArrayList<Batch>();
4.83 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
4.84 - retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
4.85 - while(end >= 2){
4.86 - int d = end % 2;
4.87 - if( d == 0 ) {
4.88 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
4.89 - } else {
4.90 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
4.91 - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
4.92 - }
4.93 - end = end / 2;
4.94 - }
4.95 - return retArray;
4.96 - }
4.97 -
4.98 - public abstract ArrayList<Batch> getBatches();
4.99 -}
5.1 --- a/src/main/java/ru/alphatech/icfpc/policy/VitalityBoostPolicy.java Sun Jun 19 13:37:56 2011 +0400
5.2 +++ b/src/main/java/ru/alphatech/icfpc/policy/VitalityBoostPolicy.java Sun Jun 19 13:38:48 2011 +0400
5.3 @@ -2,6 +2,7 @@
5.4
5.5 import java.util.ArrayList;
5.6
5.7 +import ru.alphatech.icfpc.game.AbstractPolicy;
5.8 import ru.alphatech.icfpc.game.Batch;
5.9
5.10 public class VitalityBoostPolicy extends AbstractPolicy {