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