-
Notifications
You must be signed in to change notification settings - Fork 0
/
dichotomie.js
81 lines (74 loc) · 2.33 KB
/
dichotomie.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
71
72
73
74
75
76
77
78
79
80
81
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
var inputs = readline().split(' ');
let W = parseInt(inputs[0]); // width of the building.
let H = parseInt(inputs[1]); // height of the building.
const maxTurns = parseInt(readline()); // maximum number of turns before game over.
var inputs = readline().split(' ');
const X0 = parseInt(inputs[0]);
const Y0 = parseInt(inputs[1]);
let tx = X0, ty = Y0
let turnCount = 0
let minX = 0, minY = 0
let getTarget = (bombDir) => {
console.error('W : ' + W)
console.error('H : ' + H)
console.error('max : ' + maxTurns)
console.error('x : ' + tx)
console.error('y : ' + ty)
console.error('minX : ' + minX)
console.error('minY : ' + minY)
console.error(bombDir)
turnCount++
switch (bombDir) {
case 'U':
H = ty
ty -= Math.max(Math.trunc((H - minY) / 2) + (ty < 10 ? 1 : 0), 1)
break;
case 'UR':
H = ty
ty-= Math.max(Math.trunc((H - minY) / 2), 1)
minX = tx
tx+= Math.max(Math.trunc((W - minX) / 2), 1)
break;
case 'R':
minX = tx
tx+= Math.max(Math.trunc((W - minX) / 2), 1)
break;
case 'DR':
minX = tx
tx+= Math.max(Math.trunc((W - minX) / 2), 1)
minY = ty
ty+= Math.max(Math.trunc((H - minY) / 2), 1)
break;
case 'D':
minY = ty
ty+= Math.max(Math.trunc((H - minY) / 2), 1)
break;
case 'DL':
minY = ty
ty+= Math.max(Math.trunc((H - minY) / 2), 1)
W = tx
tx-= Math.max(Math.trunc((W - minX) / 2), 1)
break;
case 'L':
W = tx
tx-= Math.max(Math.trunc((W - minX) / 2), 1)
break;
case 'UL':
W = tx
tx-= Math.max(Math.trunc((W - minX) / 2), 1)
H = ty
ty-= Math.max(Math.trunc((H - minY) / 2), 1)
break;
}
return {'x': tx, 'y': ty}
}
// game loop
while (true) {
const bombDir = readline(); // the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL)
let target = getTarget(bombDir)
console.log(target['x'] + ' ' + target['y'])
}