-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathVox-Codei-Episode-1.js
80 lines (72 loc) · 2.2 KB
/
Vox-Codei-Episode-1.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
// https://www.codingame.com/training/hard/vox-codei-episode-1
/* Helper */ fReadInts = _ =>
readline()
.split(' ')
.map(e => +e);
/* Timer */ iTimer = 3; // Turns before a bomb explodes
/* Pattern */ afImpacts = [
[[0, 0]], // Cross center
[[0, -1], [0, -2], [0, -3]], // Cross up
[[-1, 0], [-2, 0], [-3, 0]], // Cross left
[[+1, 0], [+2, 0], [+3, 0]], // Cross right
[[0, +1], [0, +2], [0, +3]]
]; // Cross down
/* Clipper */ fClip = (x, y) => {
return y > -1 && y < iH && x > -1 && x < iW ? asMap[y][x] : '';
};
/* Score */ fScore = (x, y) => {
/* Checkpnt */ var iScore = 0;
for (var aaBranch of afImpacts)
for (var aiTile of aaBranch) {
if ((s = fClip(x + aiTile[0], y + aiTile[1])) === '#') break;
iScore += s === '@' ? 1 : 0;
}
/* Passives */ if (iScore > 2)
iScore +=
+(fClip(x + 1, y + 1) == '#') * 3 +
(fClip(x + 1, y - 1) == '#') * 3 +
(fClip(x - 1, y + 1) == '#') * 3 +
(fClip(x - 1, y - 1) == '#') * 3;
return iScore;
}; // <= I know... not the determinist way to do it!
/* Explode */ fAction = (x, y) => {
/* Elapsing */ asMap.map(i => i.map((a, b, c) => (a > 0 ? c[b]-- : a)));
printErr(asMap.join('\n'));
/* Set Wait */ if (!!~'12'.indexOf(asMap[y][x])) print('WAIT');
/* Set Time */ else {
for (var aaBranch of afImpacts)
for (var aiTile of aaBranch) {
if ((s = fClip(x + aiTile[0], y + aiTile[1])) === '#') break;
if (s === '@') asMap[y + aiTile[1]][x + aiTile[0]] = '3';
}
print(iXmax + ' ' + iYmax);
}
};
[iW, iH] = fReadInts();
var asMap = [...Array(iH)].map(e => readline().split(''));
while (true) {
var iMax = 0,
iXmax,
iYmax,
aiScores = [];
/* Input Reads */ [iR, iB] = fReadInts();
/* Brute Force */ var iY = iH;
while (iY-- > 0) {
var iX = iW;
while (iX-- > 0) {
i = fScore(iX, iY);
aiScores.push([i, iX, iY]);
if (i > iMax && ~'.123'.indexOf(asMap[iY][iX])) {
iMax = i;
iXmax = iX;
iYmax = iY;
}
}
}
/* Fishy Score!*/ aiScores.sort((a, b) => a[0] < b[0]);
if (aiScores[0][0] > aiScores[1][0] * 2) {
iXmax = aiScores[1][1];
iYmax = aiScores[1][2];
}
/* Chain Bombs */ fAction(iXmax, iYmax);
}