-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlanner.java
More file actions
75 lines (65 loc) · 2.12 KB
/
Copy pathPlanner.java
File metadata and controls
75 lines (65 loc) · 2.12 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
package team048;
import java.util.LinkedList;
import battlecode.common.*;
public abstract class Planner{
private static Planner currPlanner;
protected RobotController myRC;
protected Module[] modules = new Module[ModuleType.NUM_OF_TYPES];
protected LinkedList<IdleTask> tasks = new LinkedList<IdleTask>();
protected int maxBytecodes = GameConstants.BYTECODE_LIMIT;
//TODO, find out how many it actually takes
private static final int DO_IDLE_OVERHEAD = 100;
public Planner(RobotController rc){
currPlanner = this;
myRC=rc;
}
public void init(){
for(Module m : modules){
if(m!=null){
m.init(this);
}
}
}
protected void addModule(Module module){
modules[module.getType().ordinal()]=module;
}
public Module getModule(ModuleType type){
return modules[type.ordinal()];
}
public static void doYield(){
int roundNum = Clock.getRoundNum();
if(Clock.getBytecodesLeft()>100){
Module nav = currPlanner.getModule(ModuleType.NAVIGATION);
if(nav!=null){
nav.doIdleTasks();
}
}
if(Clock.getBytecodesLeft()>20 && roundNum==Clock.getRoundNum()){
//if we have enough bytecodes to safely ensure that the yield
//happens in the right round call yield
currPlanner.myRC.yield();
}
else{
//otherwise loop till the round finishes
while(roundNum==Clock.getRoundNum()){
}
}
}
public void addIdleTask(IdleTask task){
tasks.offer(task);
}
public void doIdleTasks(){
int length = tasks.size();
while(maxBytecodes-Clock.getBytecodeNum()>500+DO_IDLE_OVERHEAD && length>0){
length--;
IdleTask currTask = tasks.pop();
if(currTask.executeTask()){
tasks.offer(currTask);
}
}
}
public void receiveMessages(int moduleIds, Message message, int intOffset,
int mapLocationOffset,int stringOffset){
//STUB
}
}