-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefaultRobot.java
More file actions
83 lines (71 loc) · 2.71 KB
/
Copy pathDefaultRobot.java
File metadata and controls
83 lines (71 loc) · 2.71 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
package team018;
import java.util.Random;
import battlecode.common.Direction;
import battlecode.common.GameActionException;
import battlecode.common.MapLocation;
import battlecode.common.Robot;
import battlecode.common.RobotController;
public abstract class DefaultRobot {
protected int roundCountChan = 32566;
protected int roundCount = 0;
protected int spawnBrodcastInt = 0;
protected static int spawnChannel[] = {50, 1000, 999, 345, 6000, 10000, 986, 666, 999, 55404, 9930, 58483, 23454};
protected static int defenseNeedChan[] = {10, 5625, 9561, 8489, 7512};
protected static int attackChan[] = {5564, 9844, 25845, 36548, 8455, 45593};
protected final RobotController rc;
protected final MapLocation enemyHQLoc;
protected final MapLocation HQLoc;
static Direction[] directions = {Direction.NORTH, Direction.NORTH_EAST, Direction.EAST, Direction.SOUTH_EAST, Direction.SOUTH, Direction.SOUTH_WEST, Direction.WEST, Direction.NORTH_WEST};
static Random rand;
DefaultRobot(RobotController rc){
this.rc = rc;
enemyHQLoc = rc.senseEnemyHQLocation();
HQLoc = rc.senseHQLocation();
rand = new Random(rc.getRobot().getID());
}
void run() {
}
protected Direction getDirTowTarAvoidMines(Direction target){
if(rc.canMove(target) && rc.senseMine(rc.getLocation().add(target)) == null){
return target;
} else if(rc.canMove(target.rotateLeft()) && rc.senseMine(rc.getLocation().add(target.rotateLeft())) == null){
return target.rotateLeft();
} else if(rc.canMove(target.rotateRight()) && rc.senseMine(rc.getLocation().add(target.rotateRight())) == null){
return target.rotateRight();
}
return target;
}
protected Direction randDirNoMines(){
boolean spotFound = false;
int i = 0;
while(i < 8 && !spotFound){
if(rc.senseMine(rc.getLocation().add(directions[i])) == null){
return directions[i];
}
}
return null;
}
protected void broadcastDataScram(int[] channel, int data) throws GameActionException{
int broadcastChan = roundCount;
while(broadcastChan > channel.length - 1){
broadcastChan = broadcastChan - (channel.length);
}
rc.broadcast(channel[broadcastChan], data);
}
protected int readDataScram(int[] channel) throws GameActionException{
int broadcastChan = roundCount;
while(broadcastChan > channel.length - 1){
broadcastChan = broadcastChan - (channel.length);
}
return rc.readBroadcast(channel[broadcastChan]);
}
protected MapLocation midLoc(MapLocation loc1, MapLocation loc2){
return new MapLocation((loc1.x + loc2.x)/2, (loc1.y + loc2.y)/2);
}
protected int senseNumBotsAtLoc(MapLocation location){
if(rc.getLocation().distanceSquaredTo(location) <= 9){
return rc.senseNearbyGameObjects(Robot.class, location, 9, rc.getTeam()).length;
}
return -1;
}
}