# HG changeset patch # User indvdum # Date 1308476328 -14400 # Node ID 1ff9e4ee2b028103fbcd24600c37cf6b8cba1df7 # Parent 26d05bc45f1d2c117595b39f68d8f6c636dc8ccd# Parent 0ffe63f2aa467a1af9740c441eae165d19d0f64f * merge diff -r 26d05bc45f1d -r 1ff9e4ee2b02 src/main/java/ru/alphatech/icfpc/cards/Get.java --- a/src/main/java/ru/alphatech/icfpc/cards/Get.java Sun Jun 19 13:37:56 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/cards/Get.java Sun Jun 19 13:38:48 2011 +0400 @@ -1,5 +1,6 @@ package ru.alphatech.icfpc.cards; +import ru.alphatech.icfpc.game.ICFPCException; import ru.alphatech.icfpc.game.IValue; import ru.alphatech.icfpc.game.Player; import ru.alphatech.icfpc.game.Value; @@ -11,11 +12,20 @@ { if (value.getClass().equals(Value.class)) { - return proponent.getSlot(((Value)value).getValue()).getValue(); + int i = ((Value)value).getValue(); + + if(i >= 0 && i <= 255) + { + return proponent.getSlot(i).getValue(); + } + else + { + throw new ICFPCException(); + } } else { - return new Value(-100); + throw new ICFPCException(); } } diff -r 26d05bc45f1d -r 1ff9e4ee2b02 src/main/java/ru/alphatech/icfpc/cards/Put.java --- a/src/main/java/ru/alphatech/icfpc/cards/Put.java Sun Jun 19 13:37:56 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/cards/Put.java Sun Jun 19 13:38:48 2011 +0400 @@ -13,7 +13,7 @@ @Override public IValue returnValue(IValue value, Player proponent, Player opponent) { - return value; + return new I(); } }; } diff -r 26d05bc45f1d -r 1ff9e4ee2b02 src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java Sun Jun 19 13:38:48 2011 +0400 @@ -0,0 +1,90 @@ +package ru.alphatech.icfpc.game; + +import java.util.ArrayList; + +import ru.alphatech.icfpc.cards.Dbl; +import ru.alphatech.icfpc.cards.ICard; +import ru.alphatech.icfpc.cards.Put; +import ru.alphatech.icfpc.cards.Succ; +import ru.alphatech.icfpc.cards.Zero; +import ru.alphatech.icfpc.game.Batch.OperationType; + +/** + * + * TODO + * + * @author akhmetovlz + * + */ +public abstract class AbstractPolicy { + + protected ArrayList batches = new ArrayList(); + + public AbstractPolicy(){ + } + + public void setRegister(int registerIndex, int num ){ + if( registerIndex < 4) { + Slot registerSlot = Run.getRegisterByIndex(registerIndex); + batches.addAll( numberIntoSlotField( registerSlot, num ) ); + } + } + + protected ArrayList numberIntoSlotField(Slot targetSlot, int number) + { + ArrayList retArray = new ArrayList(); + + IValue targetValue = targetSlot.getValue(); + + if(targetValue instanceof ICard){ + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); + } + + Value numTargetValue = (Value) targetValue; + if( numTargetValue.getValue() == number ){ + return retArray; + }else + if( numTargetValue.getValue() > number ){ + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); + retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot)); + stupidAlg(0, number, targetSlot); + }else{ + stupidAlg(numTargetValue.getValue(), number, targetSlot); + } + + return retArray; + } + + + protected ArrayList stupidAlg(int begin, int end, Slot targetSlot){ + ArrayList retArray = new ArrayList(); + while( begin*2 < end){ + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); + begin *= 2; + } + while( begin != end){ + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot)); + begin ++; + } + return retArray; + } + + protected ArrayList smartAlg(int begin, int end, Slot targetSlot){ + ArrayList retArray = new ArrayList(); + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); + retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot)); + while(end >= 2){ + int d = end % 2; + if( d == 0 ) { + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot)); + } else { + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot)); + retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot)); + } + end = end / 2; + } + return retArray; + } + + public abstract ArrayList getBatches(); +} diff -r 26d05bc45f1d -r 1ff9e4ee2b02 src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java --- a/src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java Sun Jun 19 13:37:56 2011 +0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -package ru.alphatech.icfpc.policy; - -import java.util.ArrayList; - -import ru.alphatech.icfpc.cards.Dbl; -import ru.alphatech.icfpc.cards.ICard; -import ru.alphatech.icfpc.cards.Put; -import ru.alphatech.icfpc.cards.Succ; -import ru.alphatech.icfpc.cards.Zero; -import ru.alphatech.icfpc.game.Batch; -import ru.alphatech.icfpc.game.IValue; -import ru.alphatech.icfpc.game.Player; -import ru.alphatech.icfpc.game.Run; -import ru.alphatech.icfpc.game.Slot; -import ru.alphatech.icfpc.game.Value; -import ru.alphatech.icfpc.game.Batch.OperationType; - -/** - * - * TODO - * - * @author akhmetovlz - * - */ -public abstract class AbstractPolicy { - - protected ArrayList batches = new ArrayList(); - - public AbstractPolicy(){ - } - - public void setRegister(int registerIndex, int num ){ - if( registerIndex < 4) { - Slot registerSlot = Run.getRegisterByIndex(registerIndex); - batches.addAll( numberIntoSlotField( registerSlot, num ) ); - } - } - - protected ArrayList numberIntoSlotField(Slot targetSlot, int number) - { - ArrayList retArray = new ArrayList(); - - IValue targetValue = targetSlot.getValue(); - - if(targetValue instanceof ICard){ - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); - } - - Value numTargetValue = (Value) targetValue; - if( numTargetValue.getValue() == number ){ - return retArray; - }else - if( numTargetValue.getValue() > number ){ - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); - retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot)); - stupidAlg(0, number, targetSlot); - }else{ - stupidAlg(numTargetValue.getValue(), number, targetSlot); - } - - return retArray; - } - - - protected ArrayList stupidAlg(int begin, int end, Slot targetSlot){ - ArrayList retArray = new ArrayList(); - while( begin*2 < end){ - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); - begin *= 2; - } - while( begin != end){ - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot)); - begin ++; - } - return retArray; - } - - protected ArrayList smartAlg(int begin, int end, Slot targetSlot){ - ArrayList retArray = new ArrayList(); - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); - retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot)); - while(end >= 2){ - int d = end % 2; - if( d == 0 ) { - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot)); - } else { - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot)); - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot)); - } - end = end / 2; - } - return retArray; - } - - public abstract ArrayList getBatches(); -} diff -r 26d05bc45f1d -r 1ff9e4ee2b02 src/main/java/ru/alphatech/icfpc/policy/VitalityBoostPolicy.java --- a/src/main/java/ru/alphatech/icfpc/policy/VitalityBoostPolicy.java Sun Jun 19 13:37:56 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/policy/VitalityBoostPolicy.java Sun Jun 19 13:38:48 2011 +0400 @@ -2,6 +2,7 @@ import java.util.ArrayList; +import ru.alphatech.icfpc.game.AbstractPolicy; import ru.alphatech.icfpc.game.Batch; public class VitalityBoostPolicy extends AbstractPolicy {