src/main/java/ru/alphatech/icfpc/game/AbstractPolicy.java
changeset 87 0f4c762f56f7
parent 62 3252fb664a39
child 88 9555608af847
equal deleted inserted replaced
73:50ef27b8b7dc 87:0f4c762f56f7
     1 package ru.alphatech.icfpc.game;
     1 package ru.alphatech.icfpc.game;
     2 
     2 
     3 import java.util.ArrayList;
     3 import java.util.ArrayList;
       
     4 import java.util.Collections;
       
     5 import java.util.List;
     4 
     6 
     5 import ru.alphatech.icfpc.cards.Attack;
     7 import ru.alphatech.icfpc.cards.Attack;
     6 import ru.alphatech.icfpc.cards.Dbl;
     8 import ru.alphatech.icfpc.cards.Dbl;
     7 import ru.alphatech.icfpc.cards.Get;
     9 import ru.alphatech.icfpc.cards.Get;
     8 import ru.alphatech.icfpc.cards.Help;
    10 import ru.alphatech.icfpc.cards.Help;
    72 			begin ++;
    74 			begin ++;
    73 		}
    75 		}
    74 		return retArray;
    76 		return retArray;
    75 	}
    77 	}
    76 	
    78 	
    77 	protected ArrayList<Batch> smartAlg(int begin, int end, Slot targetSlot){
    79 	protected static List<Batch> smartAlg(int begin, int end, Slot targetSlot){
    78 		ArrayList<Batch> retArray = new ArrayList<Batch>();
    80 		ArrayList<Batch> retArray = new ArrayList<Batch>();
    79 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
    81 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), targetSlot));
    80 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
    82 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), targetSlot));
       
    83 		
       
    84 		List<Batch> list1 = buildNumberOperations(0, end, targetSlot);
       
    85 		List<Batch> list2 = buildNumberOperations(begin, end, targetSlot);
       
    86 		if (list1.size() <= list2.size())
       
    87 		{
       
    88 			Collections.reverse(list1);
       
    89 			retArray.addAll(list1);
       
    90 		}
       
    91 		else
       
    92 		{
       
    93 			Collections.reverse(list2);
       
    94 			retArray.addAll(list2);
       
    95 		}
       
    96 		return retArray;
       
    97 	}
       
    98 	
       
    99 	protected static List<Batch> buildNumberOperations(int begin, int end, Slot targetSlot){
       
   100 		List<Batch> list = new ArrayList<Batch>();
       
   101 		
    81 		while(end >= 2){
   102 		while(end >= 2){
    82 			int d = end % 2;
   103 			int d = end % 2;
       
   104 			if (begin > 0 && 2*begin > end)
       
   105 			{
       
   106 				for (int i = 0; i < end - begin; i++)
       
   107 				{
       
   108 					list.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
       
   109 				}
       
   110 				break;
       
   111 			}
    83 			if( d == 0 ) {
   112 			if( d == 0 ) {
    84 				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
   113 				list.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
       
   114 				end = end / 2;
    85 			} else {
   115 			} else {
    86 				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
   116 				list.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
    87 				retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Succ(), targetSlot));
   117 				list.add(new Batch(OperationType.CARD_TO_SLOT, new Dbl() , targetSlot));
       
   118 				end = (end-1) / 2;
    88 			}
   119 			}
    89 			end = end / 2; 
       
    90 		}
   120 		}
    91 		return retArray;
   121 		return list;
    92 	}
   122 	}
    93 	
   123 	
    94 	protected ArrayList<Batch> BcombineForFunctWith3ParamsInRegister(ICard function, Slot processingSlot){
   124 	protected ArrayList<Batch> BcombineForFunctWith3ParamsInRegister(ICard function, Slot processingSlot){
    95 		ArrayList<Batch> retArray = new ArrayList<Batch>();
   125 		ArrayList<Batch> retArray = new ArrayList<Batch>();
    96 		
   126 		
   148 		
   178 		
   149 		return retArray;
   179 		return retArray;
   150 	}
   180 	}
   151 	
   181 	
   152 	public abstract ArrayList<Batch> getBatches();
   182 	public abstract ArrayList<Batch> getBatches();
       
   183 	
       
   184 	public static void main(String[] args)
       
   185 	{
       
   186 		Slot slot = new Slot();
       
   187 		List<Batch> list = smartAlg(5, 12, slot);
       
   188 		System.out.println(list.toArray().toString());
       
   189 	}
   153 }
   190 }