akhmetovlz@19: package ru.alphatech.icfpc.policy; akhmetovlz@19: akhmetovlz@32: import java.util.ArrayList; akhmetovlz@32: akhmetovlz@32: import ru.alphatech.icfpc.cards.Dbl; akhmetovlz@32: import ru.alphatech.icfpc.cards.ICard; akhmetovlz@32: import ru.alphatech.icfpc.cards.Put; akhmetovlz@38: import ru.alphatech.icfpc.cards.Succ; akhmetovlz@32: import ru.alphatech.icfpc.cards.Zero; akhmetovlz@32: import ru.alphatech.icfpc.game.Batch; akhmetovlz@32: import ru.alphatech.icfpc.game.IValue; akhmetovlz@19: import ru.alphatech.icfpc.game.Player; akhmetovlz@48: import ru.alphatech.icfpc.game.Run; akhmetovlz@32: import ru.alphatech.icfpc.game.Slot; akhmetovlz@32: import ru.alphatech.icfpc.game.Value; akhmetovlz@32: import ru.alphatech.icfpc.game.Batch.OperationType; akhmetovlz@19: akhmetovlz@38: /** akhmetovlz@38: * akhmetovlz@42: * TODO akhmetovlz@38: * akhmetovlz@38: * @author akhmetovlz akhmetovlz@38: * akhmetovlz@38: */ akhmetovlz@19: public abstract class AbstractPolicy { akhmetovlz@19: akhmetovlz@32: protected ArrayList batches = new ArrayList(); akhmetovlz@19: akhmetovlz@48: public AbstractPolicy(){ akhmetovlz@32: } akhmetovlz@32: akhmetovlz@38: public void setRegister(int registerIndex, int num ){ akhmetovlz@38: if( registerIndex < 4) { akhmetovlz@48: Slot registerSlot = Run.getRegisterByIndex(registerIndex); akhmetovlz@38: batches.addAll( numberIntoSlotField( registerSlot, num ) ); akhmetovlz@38: } akhmetovlz@19: } akhmetovlz@19: akhmetovlz@38: protected ArrayList numberIntoSlotField(Slot targetSlot, int number) akhmetovlz@32: { akhmetovlz@32: ArrayList retArray = new ArrayList(); akhmetovlz@32: akhmetovlz@32: IValue targetValue = targetSlot.getValue(); akhmetovlz@32: akhmetovlz@32: if(targetValue instanceof ICard){ akhmetovlz@32: retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); akhmetovlz@19: } akhmetovlz@32: akhmetovlz@32: Value numTargetValue = (Value) targetValue; akhmetovlz@32: if( numTargetValue.getValue() == number ){ akhmetovlz@32: return retArray; akhmetovlz@32: }else akhmetovlz@38: if( numTargetValue.getValue() > number ){ akhmetovlz@32: retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); akhmetovlz@32: retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot)); akhmetovlz@38: stupidAlg(0, number, targetSlot); akhmetovlz@38: }else{ akhmetovlz@38: stupidAlg(numTargetValue.getValue(), number, targetSlot); akhmetovlz@32: } akhmetovlz@32: akhmetovlz@32: return retArray; akhmetovlz@19: } akhmetovlz@19: akhmetovlz@38: akhmetovlz@38: protected ArrayList stupidAlg(int begin, int end, Slot targetSlot){ akhmetovlz@38: ArrayList retArray = new ArrayList(); akhmetovlz@38: while( begin*2 < end){ akhmetovlz@38: retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); akhmetovlz@38: begin *= 2; akhmetovlz@38: } akhmetovlz@38: while( begin != end){ akhmetovlz@38: retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot)); akhmetovlz@38: begin ++; akhmetovlz@38: } akhmetovlz@38: return retArray; akhmetovlz@38: } akhmetovlz@38: akhmetovlz@38: protected ArrayList smartAlg(int begin, int end, Slot targetSlot){ akhmetovlz@38: ArrayList retArray = new ArrayList(); akhmetovlz@38: retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot)); akhmetovlz@38: retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot)); akhmetovlz@38: while(end >= 2){ akhmetovlz@38: int d = end % 2; akhmetovlz@38: if( d == 0 ) { akhmetovlz@38: retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot)); akhmetovlz@38: } else { akhmetovlz@38: retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot)); akhmetovlz@38: retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot)); akhmetovlz@38: } akhmetovlz@38: end = end / 2; akhmetovlz@38: } akhmetovlz@38: return retArray; akhmetovlz@38: } akhmetovlz@41: akhmetovlz@41: public abstract ArrayList getBatches(); akhmetovlz@19: }