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(); -}