forked from RKALM/fightcodeRobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRager.js
37 lines (32 loc) · 811 Bytes
/
Rager.js
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
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot){
robot.clone();
robot.turn(45);
this.offset = 1;
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.turn(1);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot, scannedRobot = ev.scannedRobot;
if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
return;
}
robot.stop();
for (var i=0; i < 10; i++) {
robot.fire();
robot.ahead(10);
}
};
Robot.prototype.onWallCollision = function(ev) {
ev.robot.stop();
ev.robot.turn(ev.bearing - 180);
ev.robot.ahead(10)
};
Robot.prototype.onRobotCollided = function(ev) {
ev.robot.stop();
this.offset = -1 * this.offset;
ev.robot.turn(10 * this.offset);
};