src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java
changeset 101 4bb458c3548e
parent 89 b6543dcda026
child 115 21f9fa7770cc
equal deleted inserted replaced
100:875773ff406b 101:4bb458c3548e
     2 
     2 
     3 import java.util.ArrayList;
     3 import java.util.ArrayList;
     4 import java.util.Collections;
     4 import java.util.Collections;
     5 import java.util.List;
     5 import java.util.List;
     6 
     6 
     7 import ru.alphatech.icfpc.cards.Attack;
       
     8 import ru.alphatech.icfpc.cards.Dbl;
     7 import ru.alphatech.icfpc.cards.Dbl;
     9 import ru.alphatech.icfpc.cards.Get;
       
    10 import ru.alphatech.icfpc.cards.Help;
       
    11 import ru.alphatech.icfpc.cards.ICard;
     8 import ru.alphatech.icfpc.cards.ICard;
    12 import ru.alphatech.icfpc.cards.K;
       
    13 import ru.alphatech.icfpc.cards.Put;
     9 import ru.alphatech.icfpc.cards.Put;
    14 import ru.alphatech.icfpc.cards.S;
       
    15 import ru.alphatech.icfpc.cards.Succ;
    10 import ru.alphatech.icfpc.cards.Succ;
    16 import ru.alphatech.icfpc.cards.Zero;
    11 import ru.alphatech.icfpc.cards.Zero;
    17 import ru.alphatech.icfpc.game.Batch.OperationType;
    12 import ru.alphatech.icfpc.game.Batch.OperationType;
    18 
    13 
    19 /**
    14 /**
    42 		ArrayList<Batch> retArray = new ArrayList<Batch>();
    37 		ArrayList<Batch> retArray = new ArrayList<Batch>();
    43 		
    38 		
    44 		IValue targetValue = targetSlot.getValue();
    39 		IValue targetValue = targetSlot.getValue();
    45 		
    40 		
    46 		if(targetValue instanceof ICard){
    41 		if(targetValue instanceof ICard){
    47 			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
    42 			retArray.addAll(smartAlg(0, number, targetSlot));
    48 		}
       
    49 		
       
    50 		Value numTargetValue = (Value) targetValue;
       
    51 		if( numTargetValue.getValue() == number ){
       
    52 			return retArray;
       
    53 		}else
       
    54 		if( numTargetValue.getValue() > number ){
       
    55 			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
       
    56 			retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
       
    57 			stupidAlg(0, number, targetSlot);
       
    58 		}else{
    43 		}else{
    59 			stupidAlg(numTargetValue.getValue(), number, targetSlot);
    44 			Value numTargetValue = (Value) targetValue;
       
    45 			if( numTargetValue.getValue() == number ){
       
    46 				return retArray;
       
    47 			}else
       
    48 			if( numTargetValue.getValue() > number ){
       
    49 				retArray.addAll( smartAlg(0, number, targetSlot) );
       
    50 			}else{
       
    51 				retArray.addAll( smartAlg(numTargetValue.getValue(), number, targetSlot) );
       
    52 			}
    60 		}
    53 		}
    61 		
    54 		
    62 		return retArray;
    55 		return retArray;
    63 	}
    56 	}
    64 	
    57 	
    76 		return retArray;
    69 		return retArray;
    77 	}
    70 	}
    78 	
    71 	
    79 	protected static List<Batch> smartAlg(int begin, int end, Slot targetSlot){
    72 	protected static List<Batch> smartAlg(int begin, int end, Slot targetSlot){
    80 		ArrayList<Batch> retArray = new ArrayList<Batch>();
    73 		ArrayList<Batch> retArray = new ArrayList<Batch>();
    81 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
    74 		
    82 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
    75 		if(begin == 0){
       
    76 			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
       
    77 			retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
       
    78 			retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
       
    79 		}
    83 		
    80 		
    84 		List<Batch> list1 = buildNumberOperations(0, end, targetSlot);
    81 		List<Batch> list1 = buildNumberOperations(0, end, targetSlot);
    85 		List<Batch> list2 = buildNumberOperations(begin, end, targetSlot);
    82 		List<Batch> list2 = buildNumberOperations(begin, end, targetSlot);
    86 		if (list1.size() <= list2.size())
    83 		if (list1.size() <= list2.size())
    87 		{
    84 		{
   124 	public abstract ArrayList<Batch> getBatches();
   121 	public abstract ArrayList<Batch> getBatches();
   125 	
   122 	
   126 	public static void main(String[] args)
   123 	public static void main(String[] args)
   127 	{
   124 	{
   128 		Slot slot = new Slot(1);
   125 		Slot slot = new Slot(1);
   129 		List<Batch> list = smartAlg(5, 12, slot);
   126 		List<Batch> list = smartAlg(0, 8, slot);
   130 		System.out.println(list.toArray().toString());
   127 		System.out.println(list.toArray().toString());
   131 	}
   128 	}
   132 }
   129 }