src/main/java/ru/alphatech/icfpc/policy/AttackHelpPolicy.java
changeset 120 f8c080bbb572
parent 115 21f9fa7770cc
equal deleted inserted replaced
119:f2ec9adedb3b 120:f8c080bbb572
    22 
    22 
    23 	private int donorSlotIndex   = -1;
    23 	private int donorSlotIndex   = -1;
    24 	private int targetSlotIndex  = -1;
    24 	private int targetSlotIndex  = -1;
    25 	private int pointsSlotIndex  = -1;
    25 	private int pointsSlotIndex  = -1;
    26 	private int processingSlotIndex = -1;
    26 	private int processingSlotIndex = -1;
    27 	private boolean execute = false;
       
    28 	
    27 	
    29 	private TYPE type;
    28 	private TYPE type;
    30 	
    29 	
    31 	public enum TYPE {
    30 	public enum TYPE {
    32 		ATTACK,
    31 		ATTACK,
    33 		HELP
    32 		HELP
    34 	}
    33 	}
    35 	
    34 	
    36 	/**
    35 	/**
       
    36 	 * Выполнить
       
    37 	 * 
    37 	 * @param type - ATTACK or HELP
    38 	 * @param type - ATTACK or HELP
    38 	 * @param processingSlot - в какой ячейке проводить
    39 	 * @param processingSlot - в какой ячейке проводить
    39 	 * @param donor - от кого забирать хп
    40 	 * @param donor - от кого забирать хп
    40 	 * @param target - слот который надо атаковать
    41 	 * @param target - слот который надо атаковать
    41 	 * @param points - количество хп отнимаемое у донора
    42 	 * @param points - количество хп отнимаемое у донора
    42 	 * @param execute - выполнить после завершения либо просто сохранить в слоте.
       
    43 	 */
    43 	 */
    44 	public AttackHelpPolicy(TYPE type, int processingSlot, int donor, int target, int points, boolean execute) {
    44 	public AttackHelpPolicy(TYPE type, int processingSlot, int donor, int target, int points) {
    45 		this.donorSlotIndex  = donor;
    45 		this.donorSlotIndex  = donor;
    46 		this.targetSlotIndex = target;
    46 		this.targetSlotIndex = target;
    47 		this.pointsSlotIndex = points;
    47 		this.pointsSlotIndex = points;
    48 		this.processingSlotIndex = processingSlot;
    48 		this.processingSlotIndex = processingSlot; 
    49 		this.execute = execute;
       
    50 		
    49 		
    51 		this.type = type;
    50 		this.type = type;
       
    51 	}
       
    52 	
       
    53 	protected ArrayList<Batch> registerChangingBatches(Slot processingSlot){
       
    54 		ArrayList<Batch> retArray = new ArrayList<Batch>();
       
    55 		retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(2), pointsSlotIndex));
       
    56 		return retArray;
    52 	}
    57 	}
    53 	
    58 	
    54 	@Override
    59 	@Override
    55 	public ArrayList<Batch> getBatches() {
    60 	public ArrayList<Batch> getBatches() {
    56 		ArrayList<Batch> retArray = new ArrayList<Batch>();
    61 		ArrayList<Batch> retArray = new ArrayList<Batch>();
    57 		
    62 		
    58 		Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex);
    63 		Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex);
    59 		
    64 		
    60 		retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(0), donorSlotIndex));
    65 		retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(0), donorSlotIndex));
    61 		retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(1), targetSlotIndex));
    66 		retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(1), targetSlotIndex));
    62 		retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(2), pointsSlotIndex));
    67 		
       
    68 		retArray.addAll(registerChangingBatches(processingSlot));
    63 		
    69 		
    64 //		retArray.addAll(BcombineForFunctWith3ParamsInRegister(getCard(), processingSlot));
    70 //		retArray.addAll(BcombineForFunctWith3ParamsInRegister(getCard(), processingSlot));
    65 		retArray.addAll(BcombineForFunctWith3ParamsInRegister2(getCard(), processingSlot));
    71 		retArray.addAll(BcombineForFunctWith3ParamsInRegister2(getCard(), processingSlot));
    66 		
    72 		
    67 		return retArray;
    73 		return retArray;
    69 	
    75 	
    70 	public ICard getCard(){
    76 	public ICard getCard(){
    71 		return type == TYPE.ATTACK ? new Attack() : new Help();
    77 		return type == TYPE.ATTACK ? new Attack() : new Help();
    72 	}
    78 	}
    73 	
    79 	
       
    80 	protected int get3thRegisterIndex(){
       
    81 		return 2;
       
    82 	}
       
    83 	
       
    84 	protected boolean execute(){
       
    85 		return true;
       
    86 	}
    74 
    87 
    75 
    88 
    76 	/**
    89 	/**
    77 	 * С корректировкой регистров
    90 	 * С корректировкой регистров
    78 	 * @param function
    91 	 * @param function
   111 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   124 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   112 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   125 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   113 		
   126 		
   114 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
   127 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
   115 	
   128 	
   116 		retArray.addAll(correctRegister(2, processingSlot));
   129 		retArray.addAll(correctRegister(get3thRegisterIndex(), processingSlot));
   117 		
   130 		if(execute())
   118 		if(execute)
       
   119 			retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
   131 			retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
   120 		
   132 		
   121 		return retArray;
   133 		return retArray;
   122 	}
   134 	}
   123 	
   135 	
   124 	/***
       
   125 	 * @deprecated
       
   126 	 * @param function
       
   127 	 * @param processingSlot
       
   128 	 * @return
       
   129 	 */
       
   130 	protected ArrayList<Batch> BcombineForFunctWith3ParamsInRegister(ICard function, Slot processingSlot)
       
   131 	{
       
   132 		ArrayList<Batch> retArray = new ArrayList<Batch>();
       
   133 		
       
   134 		if(!(function instanceof Attack || function instanceof Help)){
       
   135 			throw new ICFPCException();
       
   136 		}
       
   137 		
       
   138 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
       
   139 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, function,  processingSlot));
       
   140 		
       
   141 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
       
   142 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
       
   143 		
       
   144 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
       
   145 		
       
   146 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
       
   147 		
       
   148 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
       
   149 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
       
   150 		
       
   151 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
       
   152 
       
   153 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
       
   154 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
       
   155 		
       
   156 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
       
   157 		
       
   158 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
       
   159 		
       
   160 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
       
   161 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
       
   162 		
       
   163 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
       
   164 
       
   165 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
       
   166 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
       
   167 		
       
   168 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
       
   169 		
       
   170 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
       
   171 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
       
   172 		
       
   173 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Succ(), processingSlot));
       
   174 		
       
   175 		if(execute)
       
   176 			retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
       
   177 		
       
   178 		return retArray;
       
   179 	}
       
   180 }
   136 }