-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
529 lines (427 loc) · 15.6 KB
/
index.html
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" type="text/css" href="static/style.css">
<link rel="icon" type="image/png" href="static/garnet.png"/>
<script src="static/globals.js"></script>
<script src="static/textFit.js"></script>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<title>The Genius Simulator</title>
</head>
<body>
<nav class="navbar navbar-expand-xl navbar-dark bg-dark">
<a class="navbar-brand">The Genius Simulator</a>
<ul class="navbar-nav mr-auto">
<li class="nav-item mr-md-3">
<a class="navbar-link" href="./games.html" style="color: white;">Game Generator</a>
</li>
<li class="nav-item mr-md-3">
<a class="navbar-link" href="./index.html" style="color: white;">Reset</a>
</li>
</ul>
<span class="navbar-text">Marcer</span>
</nav>
<div class="mt-2"></div>
<div class="container">
<div class="form-row">
<label for="players" class="mt-1 col-auto" id="count">Players (13)</label>
</div>
<div class="form-row">
<div class="dropdown mb-3 col-auto">
<button type="button" class="btn btn-info dropdown-toggle" id="dropdownDefaults" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Defaults...
</button>
<div class="form-check form-check-inline ml-1">
<input class="form-check-input" type="checkbox" value="" id="allowAnyNum">
<label class="form-check-label" for="allowAnyNum">
Allow any number of players (WARNING: the website is not optimized for >50 players)
</label>
</div>
<div class="dropdown-menu" aria-labelledby="dropdownDefaults">
<button type="button" class="dropdown-item" onclick="setPlayers(0)">The Genius S1</a>
<button type="button" class="dropdown-item" onclick="setPlayers(1)">The Genius S2</a>
<button type="button" class="dropdown-item" onclick="setPlayers(2)">The Genius S3</a>
<button type="button" class="dropdown-item" onclick="setPlayers(3)">The Genius S4</a>
<button type="button" class="dropdown-item" onclick="setPlayers(-1)">All The Genius</a>
</div>
</div>
</div>
<div class="form-row">
<div class="mb-3 col-auto">
<div id="warning"></div>
<textarea class="form-control" id="players" onchange="updatePlayerCount()" rows=7 cols=80>Minsoo, Yuram, Changyeop, Jungmoon, Jinho, Gura, Kyungran, Minseo, Poong, Sunggyu, Junseok, Sangmin, Eunji</textarea>
</div>
</div>
<a type="button" class="btn btn-primary btn-lg disabled" id="sim" onclick="simulate()" aria-disabled="true">Simulate!</a>
<div class="mt-2"></div>
<button type="button" class="btn btn-secondary" onclick="init()">INITIALIZE</button>
<button type="button" class = "btn btn-info" onclick="simToEnd()">SIM TO END</button>
<div id="title" class="mt-3"></div>
<div id="announcements" class="mt-1 mb-3"></div>
</div>
<div class="mt-2"></div>
<div class="container-fluid">
<table id="results">
</table>
</div>
<div class="mt-2"></div>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
</html>
<script>
// Globals
var players = [];
var phase = 0;
var episode = 1;
var placements = [];
var dmParticipants;
var finalScore = 0;
var length = 13;
var tableData = new Array(players.length + 3);
for (var i = 0; i < 16; i++) {
tableData[i] = new Array(players.length + 2);
if (i == 0) {
tableData[i][0] = "#";
} else if (i == 1) {
tableData[i][0] = "MM";
} else if (i == 2) {
tableData[i][0] = "DM";
} else {
tableData[i][0] = players[i-3];
}
}
function simToEnd() {
if (players.length == 0) {
init();
}
while (players.length != 0) {
simulate();
}
}
function updatePlayerCount() {
text = document.getElementById("players").value;
players = text.split(", ");
document.getElementById("count").innerHTML = "Players (" + players.length + ")";
}
function init() {
text = document.getElementById("players").value;
players = text.split(", ");
warning = document.getElementById("warning");
if (players.length != 13 && !document.getElementById('allowAnyNum').checked) {
warning.innerHTML = "The Genius needs 13 players! Currently you have " + players.length + ".";
if (!warning.classList.contains("mb-2")) {
warning.classList.add("mb-2");
}
return
} else {
warning.innerHTML = "";
warning.classList.remove("mb-2");
}
document.getElementById("title").style.display = "block";
document.getElementById("title").innerHTML = "";
document.getElementById("announcements").style.display = "block";
document.getElementById("announcements").innerHTML = "";
sim = document.getElementById("sim");
sim.classList.remove("disabled");
sim.removeAttribute("aria-disabled");
phase = 0; // 0 = MM Start, 1 = MM Results, 2 = DMO Announcement, 3 = DM Start, 4 = DM Results, 5 = Items, 6 = Finals Prep, 7 = Finals Results
episode = 1;
placements = [];
finalScore = 0;
tableData = new Array(players.length + 3);
length = players.length;
for (var i = 0; i < players.length + 3; i++) {
tableData[i] = new Array(players.length + 2);
if (i == 0) {
tableData[i][0] = "#";
} else if (i == 1) {
tableData[i][0] = "MM";
} else if (i == 2) {
tableData[i][0] = "DM";
} else {
tableData[i][0] = players[i-3];
}
}
resetResults();
// console.log("initialized!");
simulate();
}
function simulate() {
announceText = ""
switch (phase) {
case 0:
var possibleMMs = mmArray.filter(mm => mm.players == players.length);
var mm;
if (possibleMMs.length == 0 || getRandomInt(0, 100) <= 20) {
mm = generateMainMatch(players.length);
} else {
var mmChoice = getRandomInt(0, possibleMMs.length);
mm = possibleMMs[mmChoice];
}
numWinners = mm.TOLs;
// Create copy so that you can manipulate and retrieve without
// changing original list.
playersCopy = [...players];
titleText = "Main Match " + episode + ": " + mm.name + "\n";
announceText += players.length + " players remain:\n";
for (player of players) {
announceText += player + "\n";
}
tableData[0][episode] = "EP" + episode;
tableData[1][episode] = mm.name;
phase++;
break;
case 1:
var winners = [];
for (var i = 0; i < numWinners; i++) {
var winner = retrieve(playersCopy, getRandomInt(0, playersCopy.length));
winners.push(winner);
noteResult(episode, "WIN", winner);
}
var winnerText = winners.join(", ");
if (numWinners == 1) {
announceText += "The MM winner is " + winnerText + ".\n";
// Give out extra TOL only if there is a sole winner, and it's not F4 or F3.
if (players.length > 4) {
var immunity = retrieve(playersCopy, getRandomInt(0, playersCopy.length));
announceText += winner + " gives their second Token of Life to " + immunity + "." + "\n";
noteResult(episode, "IMM", immunity);
}
} else {
announceText += "The MM winners are " + winnerText + ".\n";
}
if ((players.length - numWinners) > 2) {
var loser = retrieve(playersCopy, getRandomInt(0, playersCopy.length));
var dmo = retrieve(playersCopy, getRandomInt(0, playersCopy.length));
announceText += loser + " is the Elimination Candidate." + "\n";
phase++;
} else {
var loser = playersCopy[0];
var dmo = playersCopy[1];
announceText += loser + " and " + dmo + " automatically enter the DM." + "\n";
phase += 2;
}
noteResult(episode, "EC", loser);
noteResult(episode, "DMO", dmo);
dmParticipants = [loser, dmo];
break;
case 2:
titleText = "Table of Judgement";
announceText += dmParticipants[0] + " selects " + dmParticipants[1] + " as their opponent in the DM." + "\n";
noteResult(episode, "DMO", dmParticipants[1]);
phase++;
break;
case 3:
var dm = generateDeathMatch();
titleText = "Death Match " + episode + ": " + dm + "\n";
announceText += dmParticipants[0] + " vs. " + dmParticipants[1] + "\n";
tableData[2][episode] = dm;
phase++;
break;
case 4:
var dmWinner = getRandomInt(0, 2);
var dmLoser = 1 - dmWinner;
announceText += dmParticipants[dmWinner] + " beats " + dmParticipants[dmLoser] + " in the DM." + "\n";
noteResult(episode, "ELIM", dmParticipants[dmLoser]);
index = players.indexOf(dmParticipants[dmLoser]);
placements.push(retrieve(players, index));
episode++;
if (players.length == 2) {
phase++;
} else {
phase = 0;
}
break;
case 5:
titleText = "Finals: Supporters' Choices\n";
var itemCount = [0, 0];
for (player of placements) {
var choice = getRandomInt(0, 2);
announceText += player + " chooses to support " + players[choice] + " in the Finals.\n";
noteResult(episode, players[choice], player);
itemCount[choice]++;
}
announceText += "\n" + players[0] + " receives " + itemCount[0] + " items, and " + players[1] + " receives " + itemCount[1] + " items.\n";
phase++;
break;
case 6:
var match = episode - placements.length;
var fm = generateDeathMatch();
titleText = "Final Match " + match + ": " + fm + "\n";
announceText += players[0] + " vs. " + players[1] + "\n";
if (finalScore == 0 && match == 1) {
announceText += "Tied 0 - 0\n";
} else if (finalScore == -1) {
announceText += players[0] + " leads 1 - 0\n";
} else if (finalScore == 1) {
announceText += players[1] + " leads 0 - 1\n";
} else {
announceText += "Tied 1 - 1\n";
}
tableData[0][episode] = "FM" + match;
tableData[2][episode] = fm;
phase++;
break;
case 7:
var fmWinner = getRandomInt(0, 2);
var fmLoser = 1 - fmWinner;
var match = episode - placements.length;
announceText += players[fmWinner] + " wins FM" + match + " against " + players[fmLoser] + "." + "\n";
noteResult(episode, "WIN", players[fmWinner]);
noteResult(episode, "LOSE", players[fmLoser]);
if (fmWinner == 1) {
finalScore++;
} else {
finalScore--;
}
if (Math.abs(finalScore) == 2) {
announceText += players[fmWinner] + " wins the Finals against " + players[fmLoser] + " 2-0." + "\n";
placements.push(players[fmLoser]);
placements.push(players[fmWinner]);
// hacky reset of players to guarantee chart generation
players = [];
announceText += "Congratulations!" + "\n";
sim = document.getElementById("sim");
sim.classList.add("disabled");
sim.setAttribute("aria-disabled", "true");
} else if (match == 3) {
announceText += players[fmWinner] + " wins the Finals against " + players[fmLoser] + " 2-1." + "\n";
placements.push(players[fmLoser]);
placements.push(players[fmWinner]);
// hacky reset of players to guarantee chart generation
players = [];
announceText += "Congratulations!" + "\n";
sim = document.getElementById("sim");
sim.classList.add("disabled");
sim.setAttribute("aria-disabled", "true");
} else {
episode++;
phase = 6;
}
break;
default:
announceText += "Error!" + "\n";
}
document.getElementById("announcements").innerHTML = announceText;
if (titleText) {
document.getElementById("title").innerHTML = titleText;
}
if (players.length == 0) {
makeResults();
}
}
function setPlayers(num) {
if (num == -1) {
var allArray = [];
for (playerArray of playersArrays) {
allArray.push(...playerArray);
}
// remove duplicates
allArray = [...new Set(allArray)];
document.getElementById("players").value = allArray.join(", ");
document.getElementById("allowAnyNum").checked = true;
} else {
document.getElementById("players").value = playersArrays[num].join(", ");
}
updatePlayerCount();
}
function noteResult(episode, type, player) {
// Note a result on the tableData.
for (var i = 3; i < length + 4; i++) {
if (tableData[i][0] == player) {
tableData[i][episode] = type;
break;
}
}
}
function resetResults() {
var results = document.getElementById("results");
results.innerHTML = "";
}
function makeResults() {
var results = document.getElementById("results");
// Slice out headers and only sort player data
relevantData = [...tableData].slice(3, tableData.length);
relevantData.sort(compare);
tableData.splice(-(tableData.length - 3));
tableData = tableData.concat(relevantData);
for (var i = 0; i < tableData.length; i++) {
var row = results.insertRow(-1);
var elim = false;
if (i == 0 || i == 2) {
row.classList.add("divider-row");
}
for (var j = 0; j < tableData[0].length; j++) {
var cell = row.insertCell(-1);
if (j == 0) {
cell.classList.add("first");
cell.classList.add("divider-col");
} else if (j == length - 2) {
cell.classList.add("divider-col");
}
if (tableData[i][j]) {
cell.innerHTML = tableData[i][j];
switch (tableData[i][j]) {
case "ELIM":
cell.classList.add("elim");
elim = true;
break;
case "WIN":
cell.classList.add("win");
break;
case "IMM":
cell.classList.add("imm");
break;
case "DMO":
cell.classList.add("dmo");
break;
case "EC":
cell.classList.add("ec");
break;
case "LOSE":
cell.classList.add("elim");
break;
// top two placements receive items
case placements[placements.length - 1]:
if (j != 0) {
cell.classList.add("support");
}
break;
case placements[placements.length - 2]:
if (j != 0) {
cell.classList.add("support");
}
break;
}
} else {
if (!elim) {
cell.innerHTML = "--";
}
}
textFit(cell);
}
}
}
function compare(a, b) {
// Compare function to sort table data.
if (!a.includes("ELIM") && !b.includes("ELIM")) {
var countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0);
if (countOccurrences(a, "LOSE") == 2) {
return 1
} else {
return -1
}
} else if (!a.includes("ELIM")) {
return -1
} else if (!b.includes("ELIM")){
return 1
} else {
return b.indexOf("ELIM") - a.indexOf("ELIM")
}
}
</script>