# HG changeset patch # User akhmetovlz # Date 1308476179 -14400 # Node ID 126046a2010742f65025e9c3be62863248ffdc42 # Parent eea6fcf60b730bd821300299370abffb8fb42568 (no commit message) diff -r eea6fcf60b73 -r 126046a20107 src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java --- a/src/main/java/ru/alphatech/icfpc/policy/AbstractPolicy.java Sun Jun 19 13:36:05 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(); -} diff -r eea6fcf60b73 -r 126046a20107 src/main/java/ru/alphatech/icfpc/policy/VitalityBoostPolicy.java --- a/src/main/java/ru/alphatech/icfpc/policy/VitalityBoostPolicy.java Sun Jun 19 13:36:05 2011 +0400 +++ b/src/main/java/ru/alphatech/icfpc/policy/VitalityBoostPolicy.java Sun Jun 19 13:36:19 2011 +0400 @@ -2,6 +2,7 @@ import java.util.ArrayList; +import ru.alphatech.icfpc.game.AbstractPolicy; import ru.alphatech.icfpc.game.Batch; public class VitalityBoostPolicy extends AbstractPolicy {