src/main/java/ru/alphatech/icfpc/policy/AttackHelpPolicy.java
author akhmetovlz
Mon, 20 Jun 2011 01:42:04 +0400
changeset 120 f8c080bbb572
parent 115 21f9fa7770cc
permissions -rw-r--r--
фикс багов в аттакхэдпе
     1 package ru.alphatech.icfpc.policy;
     2 
     3 import java.util.ArrayList;
     4 
     5 import ru.alphatech.icfpc.cards.Attack;
     6 import ru.alphatech.icfpc.cards.Get;
     7 import ru.alphatech.icfpc.cards.Help;
     8 import ru.alphatech.icfpc.cards.ICard;
     9 import ru.alphatech.icfpc.cards.K;
    10 import ru.alphatech.icfpc.cards.Put;
    11 import ru.alphatech.icfpc.cards.S;
    12 import ru.alphatech.icfpc.cards.Succ;
    13 import ru.alphatech.icfpc.cards.Zero;
    14 import ru.alphatech.icfpc.game.AbstractPolicy;
    15 import ru.alphatech.icfpc.game.Batch;
    16 import ru.alphatech.icfpc.game.ICFPCException;
    17 import ru.alphatech.icfpc.game.Run;
    18 import ru.alphatech.icfpc.game.Slot;
    19 import ru.alphatech.icfpc.game.Batch.OperationType;
    20 
    21 public class AttackHelpPolicy extends AbstractPolicy {
    22 
    23 	private int donorSlotIndex   = -1;
    24 	private int targetSlotIndex  = -1;
    25 	private int pointsSlotIndex  = -1;
    26 	private int processingSlotIndex = -1;
    27 	
    28 	private TYPE type;
    29 	
    30 	public enum TYPE {
    31 		ATTACK,
    32 		HELP
    33 	}
    34 	
    35 	/**
    36 	 * Выполнить
    37 	 * 
    38 	 * @param type - ATTACK or HELP
    39 	 * @param processingSlot - в какой ячейке проводить
    40 	 * @param donor - от кого забирать хп
    41 	 * @param target - слот который надо атаковать
    42 	 * @param points - количество хп отнимаемое у донора
    43 	 */
    44 	public AttackHelpPolicy(TYPE type, int processingSlot, int donor, int target, int points) {
    45 		this.donorSlotIndex  = donor;
    46 		this.targetSlotIndex = target;
    47 		this.pointsSlotIndex = points;
    48 		this.processingSlotIndex = processingSlot; 
    49 		
    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;
    57 	}
    58 	
    59 	@Override
    60 	public ArrayList<Batch> getBatches() {
    61 		ArrayList<Batch> retArray = new ArrayList<Batch>();
    62 		
    63 		Slot processingSlot = Run.getProponent().getSlot(processingSlotIndex);
    64 		
    65 		retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(0), donorSlotIndex));
    66 		retArray.addAll(numberIntoSlotField(Run.getRegisterByIndex(1), targetSlotIndex));
    67 		
    68 		retArray.addAll(registerChangingBatches(processingSlot));
    69 		
    70 //		retArray.addAll(BcombineForFunctWith3ParamsInRegister(getCard(), processingSlot));
    71 		retArray.addAll(BcombineForFunctWith3ParamsInRegister2(getCard(), processingSlot));
    72 		
    73 		return retArray;
    74 	}
    75 	
    76 	public ICard getCard(){
    77 		return type == TYPE.ATTACK ? new Attack() : new Help();
    78 	}
    79 	
    80 	protected int get3thRegisterIndex(){
    81 		return 2;
    82 	}
    83 	
    84 	protected boolean execute(){
    85 		return true;
    86 	}
    87 
    88 
    89 	/**
    90 	 * С корректировкой регистров
    91 	 * @param function
    92 	 * @param processingSlot
    93 	 * @return
    94 	 */
    95 	protected ArrayList<Batch> BcombineForFunctWith3ParamsInRegister2(ICard function, Slot processingSlot)
    96 	{
    97 		ArrayList<Batch> retArray = new ArrayList<Batch>();
    98 		
    99 		if(!(function instanceof Attack || function instanceof Help)){
   100 			throw new ICFPCException();
   101 		}
   102 				
   103 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new Put(), processingSlot));
   104 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, function,  processingSlot));
   105 		
   106 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   107 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   108 		
   109 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
   110 		
   111 		retArray.addAll(correctRegister(0, processingSlot));
   112 		
   113 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
   114 		
   115 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   116 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   117 		
   118 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
   119 
   120 		retArray.addAll(correctRegister(1, processingSlot));
   121 		
   122 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
   123 		
   124 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new K(), processingSlot));
   125 		retArray.add(new Batch(OperationType.CARD_TO_SLOT, new S(), processingSlot));
   126 		
   127 		retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Get(), processingSlot));
   128 	
   129 		retArray.addAll(correctRegister(get3thRegisterIndex(), processingSlot));
   130 		if(execute())
   131 			retArray.add(new Batch(OperationType.SLOT_TO_CARD, new Zero(), processingSlot));
   132 		
   133 		return retArray;
   134 	}
   135 	
   136 }