-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathPathfind.java
More file actions
35 lines (29 loc) · 1.2 KB
/
Pathfind.java
File metadata and controls
35 lines (29 loc) · 1.2 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
package examplefuncsplayer;
import battlecode.common.Direction;
import battlecode.common.GameActionException;
import battlecode.common.MapLocation;
import battlecode.common.RobotController;
public class Pathfind {
private static Direction dir;
public static void moveTowards(RobotController rc, MapLocation loc, boolean fill) throws GameActionException {
Direction dir = rc.getLocation().directionTo(loc);
if(rc.canMove(dir)) rc.move(dir);
else if(fill & rc.canFill(rc.getLocation().add(dir))) rc.fill(rc.getLocation().add(dir));
else {
Direction randDir = RobotPlayer.directions[RobotPlayer.random.nextInt(8)];
if(rc.canMove(randDir)) rc.move(randDir);
}
}
public static void explore(RobotController rc) throws GameActionException {
if(rc.isMovementReady()) {
MapLocation[] crumbLocs = rc.senseNearbyCrumbs(-1);
if(crumbLocs.length > 0) {
moveTowards(rc, crumbLocs[0], false);
}
if(dir == null || !rc.canMove(dir)) {
dir = RobotPlayer.directions[RobotPlayer.random.nextInt(8)];
}
if(rc.canMove(dir)) rc.move(dir);
}
}
}