-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mage.java
executable file
·95 lines (86 loc) · 3.54 KB
/
Mage.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
import bc.*;
public class Mage extends Attacker{
public Mage(int id) {
super(id);
}
@Override
public void run() {
runAttacker();
}
/**
* Attacks the enemy with most surounding enemies that it can, if no enemies reachable, will move towards them
* @return true if nothing to attack false if attacked or has enemy in range
*/
@Override
public boolean runBattleAction() {
// Team otherTeam = Player.gc.team() == Team.Blue ? Team.Red : Team.Blue;
// System.out.println("Mage id2 " + this.getId());
// VecUnit enemyUnits = Player.gc.senseNearbyUnitsByTeam(this.getLocation(), getAttackRange(), otherTeam);
//
// if (enemyUnits.size() == 0) {
// enemyUnits = Player.gc.senseNearbyUnitsByTeam(this.getLocation(), getVisionRange(), otherTeam);
// }
// if (enemyUnits.size() == 0) {
// return false;
// }
//
// if (Player.gc.isAttackReady(this.getId())) {
// Unit mostSurroundedUnit = getMostSurroundedEnemy(enemyUnits);
// int distanceToMostSurroundedUnit = (int)(this.getLocation().distanceSquaredTo(mostSurroundedUnit.location().mapLocation()));
//
// if (distanceToMostSurroundedUnit > this.getAttackRange()) {
// if (Player.gc.isMoveReady(this.getId())) {
// move(mostSurroundedUnit.location().mapLocation());
// }
// }
//
// if (Player.gc.canAttack(this.getId(), mostSurroundedUnit.id())) {
// Player.gc.attack(this.getId(), mostSurroundedUnit.id());
// }
// }
//
// return false;
if (Player.gc.isAttackReady(this.getId())) {
MapLocation enemyTargetLocation = Player.gc.unit(this.getFocusedTargetId()).location().mapLocation();
int distanceToTarget = (int)(this.getLocation().distanceSquaredTo(enemyTargetLocation));
if (distanceToTarget > this.getAttackRange()) {
if (Player.gc.isMoveReady(this.getId())) {
System.out.println("Attacker " + this.getId() + " moved forwards in combat");
this.inCombatMove(true, enemyTargetLocation);
}
}
if (Player.gc.canAttack(this.getId(), this.getFocusedTargetId())) {
Player.gc.attack(this.getId(), this.getFocusedTargetId());
System.out.println("Attacker: " + this.getId() + " attacked enemy unit " + this.getFocusedTargetId());
}
}
return false;
}
/**
* Given a VecUnit of units, will return the unit with the lowest health
* @param units the units to compare
* @return the weakest of the given units
*/
private Unit getMostSurroundedEnemy(VecUnit units) {
if (units.size() == 0) {
System.out.println("unit list was empty");
return null;
}
Unit mostSurroundedUnit = null;
int maxCount = -1;
for (int i = 0; i < units.size(); i++) {
int thisCount = 0;
Unit thisUnit = units.get(i);
for (Direction direction : Player.getMoveDirections()) {
MapLocation locationToTest = thisUnit.location().mapLocation().add(direction);
if(Player.gc.canSenseLocation(locationToTest) && Player.gc.hasUnitAtLocation(locationToTest)) {
thisCount++;
}
}
if (thisCount > maxCount) {
mostSurroundedUnit = thisUnit;
}
}
return mostSurroundedUnit;
}
}