-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMalitoWarrior.java
107 lines (83 loc) · 2.77 KB
/
MalitoWarrior.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package ia.battle.malito;
import ia.battle.core.actions.Attack;
import ia.battle.core.actions.Move;
import ia.battle.core.BattleField;
import ia.battle.core.FieldCell;
import ia.battle.core.FieldCellType;
import ia.battle.core.actions.Action;
import ia.battle.core.Warrior;
import ia.battle.core.WarriorData;
import ia.exceptions.RuleException;
import java.util.ArrayList;
import java.util.List;
public class MalitoWarrior extends Warrior {
private FieldCell lastPosition;
public MalitoWarrior(String name, int health, int defense, int strength, int speed, int range) throws RuleException {
super(name, health, defense, strength, speed, range);
}
@Override
public Action playTurn(long tick,int actionNumber) {
Action action;
int closerDistance = Integer.MAX_VALUE, distance;
BattleField batalla= BattleField.getInstance();
WarriorData enemigo = batalla.getEnemyData();
this.useSpecialItem();
if(enemigo.getInRange())
{
this.enemyKilled();
action = new Attack(enemigo.getFieldCell());
}
else
{
List<FieldCell> adj = BattleField.getInstance().getAdjacentCells(this.getPosition());
FieldCell nextMove = this.getPosition();
closerDistance = Integer.MAX_VALUE;
for(FieldCell cell : adj) {
distance = computeDistance(cell, enemigo.getFieldCell());
System.out.println("COMPUTEDISTANCE " + distance);
if ((closerDistance > distance) && (cell.getFieldCellType() != FieldCellType.BLOCKED) &&
!cell.equals(this.getPosition()) && !cell.equals(lastPosition)) {
nextMove = cell;
lastPosition = nextMove;
closerDistance = distance;
} else if(cell == lastPosition) {
System.out.println("REPITE POSICION");
this.setHealth(0);
}
}
System.out.println("La ultima posicion fue" + lastPosition);
action = new WarriorMove(nextMove);
}
return action;
}
@Override
public void wasAttacked(int damage, FieldCell source) {
// TODO Auto-generated method stub
}
@Override
public void enemyKilled() {
System.out.println("FREE KILL, ASTRAL");
}
@Override
public void worldChanged(FieldCell oldCell, FieldCell newCell) {
// TODO Auto-generated method stub
}
private int computeDistance(FieldCell source, FieldCell target) {
int distance = 0;
distance = Math.abs(target.getX() - source.getX());
distance += Math.abs(target.getY() - source.getY());
return distance;
}
class WarriorMove extends Move {
private FieldCell nextMove;
WarriorMove (FieldCell cell) {
nextMove = cell;
}
@Override
public ArrayList<FieldCell> move() {
ArrayList<FieldCell> cells = new ArrayList<FieldCell>();
cells.add(nextMove);
return cells;
}
}
}