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