# HG changeset patch # User akhmetovlz # Date 1308472543 -14400 # Node ID ede72d65975f298fe336f8d38e68543057f28d82 # Parent 6e56ba8c71c37085d68e800722d4b6c479306b50# Parent 75010a440ed03a3532d236d7e4673b769b5831a6 bla - bla - bla diff -r 6e56ba8c71c3 -r ede72d65975f src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java --- a/src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java Sun Jun 19 12:15:24 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java Sun Jun 19 12:35:43 2011 +0400 @@ -5,6 +5,7 @@ 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; @@ -13,6 +14,13 @@ import ru.alphatech.icfpc.game.Value; import ru.alphatech.icfpc.game.Batch.OperationType; +/** + * + * TODO Анализ выбора алгоритма значения для выбора алгоритма + * + * @author akhmetovlz + * + */ public abstract class AbstractPolicy { protected Player player = null; @@ -23,23 +31,17 @@ this.player = player; } - public void setRegister0( int num ){ - + public void setRegister(int registerIndex, int num ){ + if( registerIndex < 4) { + Slot registerSlot = player.getRegisterByIndex(registerIndex); + batches.addAll( numberIntoSlotField( registerSlot, num ) ); + } } - public void setRegister1( int num ){ - - } - - public void setRegister2( int num ){ - - } - - protected ArrayList numberIntoSlotField(int slot, int number) + protected ArrayList numberIntoSlotField(Slot targetSlot, int number) { ArrayList retArray = new ArrayList(); - Slot targetSlot = player.getSlot(slot); IValue targetValue = targetSlot.getValue(); if(targetValue instanceof ICard){ @@ -50,28 +52,45 @@ if( numTargetValue.getValue() == number ){ return retArray; }else - if( numTargetValue.getValue() < number ){ - int buffValue = numTargetValue.getValue(); - while( buffValue*2 < number){ - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); - } - while( buffValue != number){ - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); - } - }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)); - int buffValue = numTargetValue.getValue(); - while( buffValue*2 < number){ - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), targetSlot)); - } - while( buffValue != number){ - retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl(), 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; + } }