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@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@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@19: public abstract class AbstractPolicy { akhmetovlz@19: akhmetovlz@19: protected Player player = null; akhmetovlz@19: akhmetovlz@32: protected ArrayList batches = new ArrayList(); akhmetovlz@19: akhmetovlz@32: public AbstractPolicy(Player player){ akhmetovlz@19: this.player = player; akhmetovlz@32: } akhmetovlz@32: akhmetovlz@32: public void setRegister0( int num ){ akhmetovlz@32: akhmetovlz@19: } akhmetovlz@19: akhmetovlz@32: public void setRegister1( int num ){ akhmetovlz@32: akhmetovlz@19: } akhmetovlz@19: akhmetovlz@32: public void setRegister2( int num ){ akhmetovlz@32: akhmetovlz@19: } akhmetovlz@19: akhmetovlz@32: protected ArrayList numberIntoSlotField(int slot, int number) akhmetovlz@32: { akhmetovlz@32: ArrayList retArray = new ArrayList(); akhmetovlz@32: akhmetovlz@32: Slot targetSlot = player.getSlot(slot); 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@32: if( numTargetValue.getValue() < number ){ akhmetovlz@32: int buffValue = numTargetValue.getValue(); akhmetovlz@32: while( buffValue*2 < number){ akhmetovlz@32: retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); akhmetovlz@32: } akhmetovlz@32: while( buffValue != number){ akhmetovlz@32: retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); akhmetovlz@32: } akhmetovlz@32: }else{ 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@32: int buffValue = numTargetValue.getValue(); akhmetovlz@32: while( buffValue*2 < number){ akhmetovlz@32: retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); akhmetovlz@32: } akhmetovlz@32: while( buffValue != number){ akhmetovlz@32: retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); akhmetovlz@32: } akhmetovlz@32: } akhmetovlz@32: akhmetovlz@32: return retArray; akhmetovlz@32: akhmetovlz@19: } akhmetovlz@19: akhmetovlz@19: }