-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathAespitia.java
More file actions
88 lines (73 loc) · 2.5 KB
/
Aespitia.java
File metadata and controls
88 lines (73 loc) · 2.5 KB
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
package esi18;
import battleship.core.*;
import java.util.List;
/*
* SimpleShip
* @author Your Name
*/
public class Aespitia extends Ship {
public Aespitia() {
this.initializeName("Aespitia");
this.initializeOwner("Your Name");
this.initializeHull(1);
this.initializeFirepower(2);
this.initializeSpeed(1);
this.initializeRange(6);
}
/*
* Determines what actions the ship will take on a given turn
* @param arena (Arena) the battlefield for the match
* @return void
*/
@Override
protected void doTurn(Arena arena) {
List<Ship> nearby = this.getNearbyShips(arena);
int numFriends=0;
int numShots = this.getRemainingShots();
// loop through the list of nearby ships
Ship focus = nearby.get(0);
for (int i = 0; i < nearby.size(); i++) {
if ( this.isSameTeamAs(nearby.get(i)) ) {
// if same team, don't shoot
numFriends = numFriends + 1;
}
else {
Ship enemy = nearby.get(i);
Coord enemyLoc = enemy.getCoord();
int x = enemyLoc.getX();
int y = enemyLoc.getY();
while(enemy.getHealth() > 0 && numShots > 0) {
this.fire(arena, x, y);
numShots = this.getRemainingShots();
}
}
}
if ( nearby.size() > numFriends ) {
//boat shouldnt move East, because nearby ship is greater than 0
}
else{
this.move(arena,Direction.EAST);
}
nearby = this.getNearbyShips(arena);
numFriends = 0;
numShots = this.getRemainingShots();
// loop through the list of nearby ships
focus = nearby.get(0);
for (int i = 0; i < nearby.size(); i++) {
if ( this.isSameTeamAs(nearby.get(i)) ) {
// if same team, don't shoot
numFriends = numFriends + 1;
}
else {
Ship enemy = nearby.get(i);
Coord enemyLoc = enemy.getCoord();
int x = enemyLoc.getX();
int y = enemyLoc.getY();
while(enemy.getHealth() > 0 && numShots > 0) {
this.fire(arena, x, y);
numShots = this.getRemainingShots();
}
}
}
}
}