-
Notifications
You must be signed in to change notification settings - Fork 0
/
community.html
654 lines (539 loc) · 20.7 KB
/
community.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
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
<!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/sheet.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: Community Edition (Stat-Based)</title>
</head>
<body>
<nav class="navbar navbar-expand-xl navbar-dark bg-dark">
<a class="navbar-brand">The Genius Simulator: Community Edition (Stat-Based)</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="./community.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)">Zero's Gambit</a>
<button type="button" class="dropdown-item" onclick="setPlayers(1)">Zero's Gauntlet</a>
<button type="button" class="dropdown-item" onclick="setPlayers(2)">The Genius: Tabula Rasa</a>
<button type="button" class="dropdown-item" onclick="setPlayers(3)">The Genius: Deadly Influx</a>
<button type="button" class="dropdown-item" onclick="setPlayers(4)">Genius Game 4</a>
<button type="button" class="dropdown-item" onclick="setPlayers(5)">Master of All Trades</a>
<button type="button" class="dropdown-item" onclick="setPlayers(6)">Genius Invitational</a>
<button type="button" class="dropdown-item" onclick="setPlayers(7)">The Genius: Yin and Yang</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>Isa, Deusovi, Jihyo, Jiffa, e_is_cool, chaotic_iak, relay400, Meladog, Heol, RedsToad, VicariousShaner, AZNDEVIL, MathTurtle</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/popper.js@1.16.0/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);
var itemCount = [0, 0];
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];
}
}
class Player {
constructor(name, dm_rate, mm_rate, dodge_rate, safe_rate) {
this.name = name;
if (dm_rate == "Never in DM") {
this.dm_rate = 37.0;
} else {
this.dm_rate = Math.min(100.0, Number.parseFloat(dm_rate.replace("%", "")));
}
this.mm_rate = Math.min(100.0, Number.parseFloat(mm_rate.replace("%", "")));
if (dodge_rate == "Always immune") {
this.dodge_rate == 100.0;
} else {
this.dodge_rate = Math.min(100.0, Number.parseFloat(dodge_rate.replace("%", "")));
}
this.safe_rate = Math.min(100.0, Number.parseFloat(safe_rate.replace("%", "")));
}
}
function updatePlayerCount() {
text = document.getElementById("players").value;
players = text.split(", ");
document.getElementById("count").innerHTML = "Players (" + players.length + ")";
}
function simToEnd() {
if (players.length == 0) {
init();
}
while (players.length != 0) {
simulate();
}
}
function init() {
text = document.getElementById("players").value;
player_names = text.split(", ");
players = [];
for (name of player_names) {
for (row of sheet) {
var valid_names = row[0].split("/");
var valid_names = valid_names.map((names) => names.trim().toLowerCase());
if (valid_names.includes(name.toLowerCase())) {
players.push(new Player(name, row[10], row[9], row[12], row[11]));
break;
}
if (sheet.indexOf(row) == sheet.length - 1) {
console.log("End of loop. Could not find: " + name);
}
}
}
//console.log(players)
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].name;
}
}
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) <= 5) {
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.name + "\n";
}
tableData[0][episode] = "EP" + episode;
tableData[1][episode] = mm.name;
phase++;
break;
case 1:
var winners = [];
for (var i = 0; i < numWinners; i++) {
// reset every time because playersCopy mutates
var win_chances = [];
for (player of playersCopy) {
win_chances.push(player.mm_rate + 5);
}
// roll random int between 0 and floor(sum)
var value = getRandomInt(0, Math.floor(win_chances.reduce((partialSum, a) => partialSum + a, 0)));
var index = getSumIndex(win_chances, value);
//console.log(win_chances);
//console.log(value);
var winner = retrieve(playersCopy, index);
//console.log(winner);
winners.push(winner.name);
noteResult(episode, "WIN", winner.name);
}
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 win_chances = [];
for (player of playersCopy) {
win_chances.push(player.mm_rate + 5);
}
var value = getRandomInt(0, Math.floor(win_chances.reduce((partialSum, a) => partialSum + a, 0)));
var index = getSumIndex(win_chances, value);
//console.log(win_chances);
//console.log(value);
var immunity = retrieve(playersCopy, index);
//console.log(immunity);
announceText += winner.name + " gives their second Token of Life to " + immunity.name + "." + "\n";
noteResult(episode, "IMM", immunity.name);
}
} else {
announceText += "The MM winners are " + winnerText + ".\n";
}
if ((players.length - numWinners) > 2) {
var lose_chances = [];
for (player of playersCopy) {
lose_chances.push(100 - player.safe_rate + 5);
}
var value = getRandomInt(0, Math.floor(lose_chances.reduce((partialSum, a) => partialSum + a, 0)));
var index = getSumIndex(lose_chances, value);
//console.log(lose_chances);
//console.log(value);
var loser = retrieve(playersCopy, index);
//console.log(loser);
var dodge_chances = [];
for (player of playersCopy) {
dodge_chances.push(100 - player.dodge_rate + 5);
}
var value = getRandomInt(0, Math.floor(dodge_chances.reduce((partialSum, a) => partialSum + a, 0)));
var index = getSumIndex(dodge_chances, value);
//console.log(dodge_chances);
//console.log(value);
var dmo = retrieve(playersCopy, index);
//console.log(dmo);
announceText += loser.name + " is the Elimination Candidate." + "\n";
phase++;
} else {
var loser = playersCopy[0];
var dmo = playersCopy[1];
announceText += loser.name + " and " + dmo.name + " automatically enter the DM." + "\n";
phase += 2;
}
noteResult(episode, "EC", loser.name);
noteResult(episode, "DMO", dmo.name);
dmParticipants = [loser, dmo];
break;
case 2:
titleText = "Table of Judgement";
announceText += dmParticipants[0].name + " selects " + dmParticipants[1].name + " as their opponent in the DM." + "\n";
noteResult(episode, "DMO", dmParticipants[1].name);
phase++;
break;
case 3:
var dmChoice = getRandomInt(0, dmArray.length);
titleText = "Death Match " + episode + ": " + dmArray[dmChoice] + "\n";
announceText += dmParticipants[0].name + " vs. " + dmParticipants[1].name + "\n";
tableData[2][episode] = dmArray[dmChoice];
phase++;
break;
case 4:
var dm_chances = [dmParticipants[0].dm_rate + 5, dmParticipants[1].dm_rate + 5];
var value = getRandomInt(0, Math.floor(dm_chances.reduce((partialSum, a) => partialSum + a, 0)));
var dmWinner = getSumIndex(dm_chances, value);
//console.log(dm_chances);
//console.log(value);
var dmLoser = 1 - dmWinner;
announceText += dmParticipants[dmWinner].name + " beats " + dmParticipants[dmLoser].name + " in the DM." + "\n";
noteResult(episode, "ELIM", dmParticipants[dmLoser].name);
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";
itemCount = [0, 0];
var item_chances = [];
for (player of players) {
safe_and_dodge_eps = (episode - 1) - (getResults("DMO", player.name) + getResults("EC", player.name));
item_chances.push((safe_and_dodge_eps / (episode - 1) * 20)); // this 20 was chosen arbitrarily.
}
if (item_chances[0] > item_chances[1]) {
item_chances[1] = 50 - item_chances[0];
item_chances[0] = 50 + item_chances[0];
} else {
item_chances[0] = 50 - item_chances[1];
item_chances[1] = 50 + item_chances[1];
}
for (player of placements) {
var value = getRandomInt(0, Math.floor(item_chances.reduce((partialSum, a) => partialSum + a, 0)));
var choice = getSumIndex(item_chances, value);
announceText += player.name + " chooses to support " + players[choice].name + " in the Finals.\n";
noteResult(episode, players[choice].name, player.name);
itemCount[choice]++;
}
announceText += "\n" + players[0].name + " receives " + itemCount[0] + " items, and " + players[1].name + " receives " + itemCount[1] + " items.\n";
phase++;
break;
case 6:
var match = episode - placements.length;
var fmChoice = getRandomInt(0, dmArray.length);
titleText = "Final Match " + match + ": " + dmArray[fmChoice] + "\n";
announceText += players[0].name + " vs. " + players[1].name + "\n";
if (finalScore == 0 && match == 1) {
announceText += "Tied 0 - 0\n";
} else if (finalScore == -1) {
announceText += players[0].name + " leads 1 - 0\n";
} else if (finalScore == 1) {
announceText += players[1].name + " leads 0 - 1\n";
} else {
announceText += "Tied 1 - 1\n";
}
tableData[0][episode] = "FM" + match;
tableData[2][episode] = dmArray[fmChoice];
phase++;
break;
case 7:
var item_sum = itemCount.reduce((partialSum, a) => partialSum + a, 0);
var fm_chances = [(players[0].dm_rate + 5) * (itemCount[0] + item_sum / item_sum), (players[1].dm_rate + 5) * (itemCount[1] + item_sum / item_sum)];
//console.log(players);
//console.log(fm_chances);
var value = getRandomInt(0, Math.floor(fm_chances.reduce((partialSum, a) => partialSum + a, 0)));
var fmWinner = getSumIndex(fm_chances, value);
var fmLoser = 1 - fmWinner;
var match = episode - placements.length;
announceText += players[fmWinner].name + " wins FM" + match + " against " + players[fmLoser].name + "." + "\n";
noteResult(episode, "WIN", players[fmWinner].name);
noteResult(episode, "LOSE", players[fmLoser].name);
if (fmWinner == 1) {
finalScore++;
} else {
finalScore--;
}
if (Math.abs(finalScore) == 2) {
announceText += players[fmWinner].name + " wins the Finals against " + players[fmLoser].name + " 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].name + " wins the Finals against " + players[fmLoser].name + " 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 (commArray of commArrays) {
allArray.push(...commArray);
}
// remove duplicates
allArray = [...new Set(allArray)];
document.getElementById("players").value = allArray.join(", ");
document.getElementById("allowAnyNum").checked = true;
} else {
document.getElementById("players").value = commArrays[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 getResults(type, player) {
// Get the occurrences of a type of result in tableData for a player.
var count = 0;
for (var i = 3; i < length + 4; i++) {
if (tableData[i][0] == player) {
for (var j = 0; j < tableData[i].length; j++) {
if (tableData[i][j] == type) {
count += 1;
}
}
break;
}
}
return count;
}
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].name:
if (j != 0) {
cell.classList.add("support");
}
break;
case placements[placements.length - 2].name:
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>