forked from davidramirezm30/Hackathon-Redradix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
robot.js
70 lines (69 loc) · 2.18 KB
/
robot.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
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
async function main(tank) {
let range = 0
let x = 0
let posX = await tank.getX();
let posY = await tank.getY();
console.log(posX, posY)
if (posX == 628 && posY == 833) x = 225;
if (posX == 628 && posY == 167) x = 45;
if (posX == 294 && posY == 500) x = 315;
if (posX == 961 && posY == 500) x = 135;
while (true) {
if (await tank.scan(x, 10) !== 0 ) {
x += 5 - Number(await tank.scan(x - 5, 5) !== 0) * 10;
if ((range = await tank.scan(x, 10)) > 20) {
await tank.shoot(x, range + 5)
if (range > 200) await tank.drive(x, 50)
else {
if (await tank.getX() > 150 && await tank.getX() < 1150 && await tank.getY() > 150 && await tank.getY() < 850)
await tank.drive(180 - x, 0);
else {
if (await tank.getX()<=150){
await tank.drive(0, 100);
while (await tank.getX()<=150);
await tank.drive(0, 0);
}
if (await tank.getX() >= 1150){
await tank.drive(180, 100);
while (await tank.getX() >= 1150);
await tank.drive(0, 0);
}
if (await tank.getY() <= 150){
await tank.drive(90, 100);
while (await tank.getY() <=150);
await tank.drive(0, 0);
}
if (await tank.getY() >= 850){
await tank.drive(270, 100);
while (await tank.getY() >= 850);
await tank.drive(0, 0);
}
}
}
}
x -= 20
} else {
x += 20
if (await tank.getX()<=150){
await tank.drive(0, 100);
while (await tank.getX()<=150);
await tank.drive(0, 0);
}
if (await tank.getX() >= 1150){
await tank.drive(180, 100);
while (await tank.getX() >= 1150);
await tank.drive(0, 0);
}
if (await tank.getY() <= 150){
await tank.drive(90, 100);
while (await tank.getY() <=150);
await tank.drive(0, 0);
}
if (await tank.getY() >= 850){
await tank.drive(270, 100);
while (await tank.getY() >= 850);
await tank.drive(0, 0);
}
}
}
}