forked from mangin/HW0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
41 lines (35 loc) · 1.16 KB
/
main.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
/*global readline: false, print: false */
(function () {
'use strict';
var inputs, W, H, X0, Y0, l, r, u, d, BOMB_DIR, x, y;
inputs = readline().split(' ');
W = parseInt(inputs[0], 10); // width of the building.
H = parseInt(inputs[1], 10); // height of the building.
parseInt(readline(), 10); // maximum number of turns before game over.
inputs = readline().split(' ');
X0 = parseInt(inputs[0], 10);
Y0 = parseInt(inputs[1], 10);
l = 0;
r = W - 1;
u = 0;
d = H - 1;
// game loop
while (true) {
BOMB_DIR = readline(); // the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL)
if (BOMB_DIR.indexOf('L') >= +0) {
r = X0 - 1;
} else if (BOMB_DIR.indexOf('R') >= +0) {
l = X0 + 1;
}
if (BOMB_DIR.charAt(0) === 'U') {
d = Y0 - 1;
} else if (BOMB_DIR.charAt(0) === 'D') {
u = Y0 + 1;
}
X0 = Math.round((l + r) / 2);
Y0 = Math.round((u + d) / 2);
x = X0;
y = Y0;
print(x + " " + y); // the location of the next window Batman should jump to.
}
}());