forked from jatloe/RandomWebsite1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cd_sim.html
294 lines (283 loc) · 19.8 KB
/
cd_sim.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
<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="jatloesmile-hd.png">
<title>CDR Simulator</title>
<style>
.font{
font-size: 18px;
font-family: Georgia;
}
body {
font-family: Georgia;
text-align: center;
}
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content/Box */
.modal-content {
background-color: #fefefe;
margin: 15% auto; /* 15% from the top and centered */
padding: 20px;
border: 1px solid #888;
width: 80%; /* Could be more or less, depending on screen size */
}
/* The Close Button */
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body>
<p>V1.42</p>
<p>Credits to mathemolympiad for putting problems and CSS!</p>
<p>Credits also to AMC 8 and mathleague.orgfor making good countdown questions available!</p>
<a href="cd_sim_explain.html">How does this work?</a>
<p id="tocopy"></p>
<button type="button" onclick="importOpponent()" id="importbutton" class="font">Import Opponent</button> <br>
<img src="https://cdn.discordapp.com/attachments/984414857073946636/984606882075410482/unknown.png" alt="Problem" id="problem"> <br><br>
<button type="button" onclick="start()" id="startbutton" class="font">Start</button>
<button type="button" onclick="buzz()" id="buzzbutton" class="font" disabled>Buzz</button><br>
<input type="text" id="answer" class="font" disabled><br>
<p>Status: <b><span id="result" class="font">The game has not started.</span></b></p>
<p>Score: <b><span id="score" class="font">0 you - 0 opponent</span></b></p>
<button type="button" class="font" id="myBtn">Formatting Tips</button>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close"><button>X</button></span>
<h3>Formatting Tips:</h3>
<p>No commas between digits. If your answer is a fraction or mixed number, enter it as something like 3/2 or 1 1/2 with no spaces, if it is a square root, enter it as something like 6 sqrt(3). If it is a decimal, just write the number, like 1.5. If it is a percent, do not include the percent symbol, just write it as something like 50.</p>
</div>
</div>
<p style="font-size:11px;">Modal code credits to W3Schools!</p>
</body>
<script>
var sha256=function a(b){function c(a,b){return a>>>b|a<<32-b}for(var d,e,f=Math.pow,g=f(2,32),h="length",i="",j=[],k=8*b[h],l=a.h=a.h||[],m=a.k=a.k||[],n=m[h],o={},p=2;64>n;p++)if(!o[p]){for(d=0;313>d;d+=p)o[d]=p;l[n]=f(p,.5)*g|0,m[n++]=f(p,1/3)*g|0}for(b+="\x80";b[h]%64-56;)b+="\x00";for(d=0;d<b[h];d++){if(e=b.charCodeAt(d),e>>8)return;j[d>>2]|=e<<(3-d)%4*8}for(j[j[h]]=k/g|0,j[j[h]]=k,e=0;e<j[h];){var q=j.slice(e,e+=16),r=l;for(l=l.slice(0,8),d=0;64>d;d++){var s=q[d-15],t=q[d-2],u=l[0],v=l[4],w=l[7]+(c(v,6)^c(v,11)^c(v,25))+(v&l[5]^~v&l[6])+m[d]+(q[d]=16>d?q[d]:q[d-16]+(c(s,7)^c(s,18)^s>>>3)+q[d-7]+(c(t,17)^c(t,19)^t>>>10)|0),x=(c(u,2)^c(u,13)^c(u,22))+(u&l[1]^u&l[2]^l[1]&l[2]);l=[w+x|0].concat(l),l[4]=l[4]+w|0}for(d=0;8>d;d++)l[d]=l[d]+r[d]|0}for(d=0;8>d;d++)for(e=3;e+1;e--){var y=l[d]>>8*e&255;i+=(16>y?0:"")+y.toString(16)}return i};
const problems = [
['https://cdn.discordapp.com/attachments/928190196443394128/983858397780783164/unknown.png', 'a73b320dc0d3a57c03f897eb28ca91e623c5ee635db59476ba3178c90b94019f'],
['https://cdn.discordapp.com/attachments/928190196443394128/983858433507868712/unknown.png', '5ec1a0c99d428601ce42b407ae9c675e0836a8ba591c8ca6e2a2cf5563d97ff0'],
['https://cdn.discordapp.com/attachments/928190196443394128/983858515309396028/unknown.png', 'c63efd61a70d0f6b7e5de2b9e0c36adfae6d760613271650c71c90df16c71344'],
['https://cdn.discordapp.com/attachments/928190196443394128/983858953865822228/unknown.png', '52e90ae24326591c8161e2e05a8f3b9b57287ca13aba3be7e84043691e160ba6'],
['https://cdn.discordapp.com/attachments/928190196443394128/983859056487837766/unknown.png', 'd4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35'],
['https://cdn.discordapp.com/attachments/928190196443394128/983859239460151406/unknown.png', '5f0fbfc126a9876e177921aeb69a9705447e5b4f29fc96631ab4ac6d31c62717'],
['https://cdn.discordapp.com/attachments/983923226193301524/983923245277380608/unknown.png', 'dd8e8c8c9dae8978f122d7bcf3d0d49f6a0e86b9fc35528f55e78f7408927bb1'],
['https://cdn.discordapp.com/attachments/983923226193301524/983923424508403762/unknown.png', '9775a97df5faff567f02c64c4762263379b3e0471c26186e8938e47ffe074045'],
['https://cdn.discordapp.com/attachments/983923226193301524/983923688724369420/unknown.png', 'e7f6c011776e8db7cd330b54174fd76f7d0216b612387a5ffcfb81e6f0919683'],
['https://cdn.discordapp.com/attachments/983923226193301524/983923834430300250/unknown.png', 'd8c70c790b932498919043bf8e58348c481d9b874598c9557fc105c0f1eae803'],
['https://cdn.discordapp.com/attachments/928996066894962718/984196821037514843/unknown.png', 'a512db2741cd20693e4b16f19891e72b9ff12cead72761fc5e92d2aaf34740c1'],
['https://cdn.discordapp.com/attachments/928996066894962718/984196860593983578/unknown.png', '3fdba35f04dc8c462986c992bcf875546257113072a909c162f7e470e581e278'],
['https://cdn.discordapp.com/attachments/928996066894962718/984196888267984986/unknown.png', 'e629fa6598d732768f7c726b4b621285f9c3b85303900aa912017db7617d8bdb'],
['https://cdn.discordapp.com/attachments/928996066894962718/984197008250245130/unknown.png', '8241649609f88ccd2a0a5b233a07a538ec313ff6adf695aa44a969dbca39f67d'],
['https://cdn.discordapp.com/attachments/928996066894962718/984197055742353418/unknown.png', 'ef2d127de37b942baad06145e54b0c619a1f22327b2ebbcfbec78f5564afe39d'],
['https://cdn.discordapp.com/attachments/928996066894962718/984197085966499850/unknown.png', '4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce'],
['https://cdn.discordapp.com/attachments/928996066894962718/984197168770457641/unknown.png', '6b51d431df5d7f141cbececcf79edf3dd861c3b4069f0b11661a3eefacbba918'],
['https://cdn.discordapp.com/attachments/928996066894962718/984197191570714654/unknown.png', '4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a'],
['https://cdn.discordapp.com/attachments/928996066894962718/984202452301660160/unknown.png', 'b5759d9d328794e68225a6720de74b8cc4377cd31e4f7f7311f269a95ae5c86b'],
['https://cdn.discordapp.com/attachments/928996066894962718/984202495112917052/unknown.png', '4ec9599fc203d176a301536c2e091a19bc852759b255bd6818810a42c5fed14a'],
['https://cdn.discordapp.com/attachments/928996066894962718/984202533251731456/unknown.png', '170b6fbc9474e95f607d477059c3c48ff15439a74041d912f83b384ab1e15820'],
['https://cdn.discordapp.com/attachments/928996066894962718/984202588595580928/unknown.png', '4ec9599fc203d176a301536c2e091a19bc852759b255bd6818810a42c5fed14a'],
['https://cdn.discordapp.com/attachments/928996066894962718/984202619864100995/unknown.png', '84b504f830bf8b6d2c233eead51d27a08d46a33ddf8225d90197e3f565f5d621'],
['https://cdn.discordapp.com/attachments/928996066894962718/984202689388896356/unknown.png', '6523f09afbc5ba27530a3abe3ff0f5db40b2b859346f4425d64edd6d596c6eb5'],
['https://cdn.discordapp.com/attachments/928996066894962718/984202716882567168/unknown.png', '4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce'],
['https://cdn.discordapp.com/attachments/928996066894962718/984202748671193088/unknown.png', 'e7f6c011776e8db7cd330b54174fd76f7d0216b612387a5ffcfb81e6f0919683'],
['https://cdn.discordapp.com/attachments/928996066894962718/984203542833266728/unknown.png', '30182b97b6f6a92441bfc0afc8189e0316d207a30a6edcade5fcfa7d9b3ca2c7'],
['https://cdn.discordapp.com/attachments/928996066894962718/984203573640450148/unknown.png', '3fdba35f04dc8c462986c992bcf875546257113072a909c162f7e470e581e278'],
['https://cdn.discordapp.com/attachments/928996066894962718/984203603751370752/unknown.png', '7902699be42c8a8e46fbbb4501726517e86b22c56a189f7625a6da49081b2451'],
['https://cdn.discordapp.com/attachments/983923226193301524/985720656752676894/unknown.png', '6af1f692e9496c6d0b668316eccb93276ae6b6774fa728aac31ff40a38318760'],
['https://cdn.discordapp.com/attachments/983923226193301524/985721056348237824/unknown.png', '2ac878b0e2180616993b4b6aa71e61166fdc86c28d47e359d0ee537eb11d46d3'],
['https://cdn.discordapp.com/attachments/983923226193301524/985721308211978260/unknown.png', '5f9c4ab08cac7457e9111a30e4664920607ea2c115a1433d7be98e97e64244ca'],
['https://cdn.discordapp.com/attachments/983923226193301524/985721501527453696/unknown.png', '69f59c273b6e669ac32a6dd5e1b2cb63333d8b004f9696447aee2d422ce63763'],
['https://cdn.discordapp.com/attachments/983923226193301524/985721821582225479/unknown.png', 'c83b76ed227dba78fb1b8862d61db21f408ef883837595fd52ad812c7354d287'],
['https://cdn.discordapp.com/attachments/983923226193301524/985722178643304568/unknown.png', '03a3d955b8799a90f1ff5a39479fde8e618f8ca3282d5b187186f2cf361abd32'],
['https://cdn.discordapp.com/attachments/983923226193301524/985722407341940826/unknown.png', '76a50887d8f1c2e9301755428990ad81479ee21c25b43215cf524541e0503269'],
['https://cdn.discordapp.com/attachments/983923226193301524/985722608425246795/unknown.png', '72d73db944cf6d9a5f11d6c073c1dce0bde28a4d2341caf4ae976e858c62cabc'],
['https://cdn.discordapp.com/attachments/983923226193301524/985722824503226388/unknown.png', '6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b'],
['https://cdn.discordapp.com/attachments/983923226193301524/985722990639599696/unknown.png', 'e7f6c011776e8db7cd330b54174fd76f7d0216b612387a5ffcfb81e6f0919683'],
['https://cdn.discordapp.com/attachments/983923226193301524/992031135976661002/unknown.png', '85d6385b945c0d602103db39b0b654b2af93b5127938e26a959c123f0789b948'],
['https://cdn.discordapp.com/attachments/983923226193301524/992031490131111986/unknown.png', 'ec43abf78948fa60728914675846d1faf7f743e9741bf38e7d062f2ac6530d4d'],
['https://cdn.discordapp.com/attachments/983923226193301524/992031667524993075/unknown.png', '81b8a03f97e8787c53fe1a86bda042b6f0de9b0ec9c09357e107c99ba4d6948a'],
['https://cdn.discordapp.com/attachments/983923226193301524/992031890573901934/unknown.png', '7b69759630f869f2723875f873935fed29d2d12b10ef763c1c33b8e0004cb405'],
['https://cdn.discordapp.com/attachments/983923226193301524/992032059763740682/unknown.png', 'd9a5223b761c375d1263e6e57ebec42d3e0fe3f6f283488d2eb204fb6ff17ee5'],
['https://cdn.discordapp.com/attachments/983923226193301524/993333156679794768/unknown.png', '4fc82b26aecb47d2868c4efbe3581732a3e7cbcc6c2efb32062c08170a05eeb8'],
['https://cdn.discordapp.com/attachments/983923226193301524/993333395486691328/unknown.png', '6b51d431df5d7f141cbececcf79edf3dd861c3b4069f0b11661a3eefacbba918'],
['https://cdn.discordapp.com/attachments/983923226193301524/993333558498295908/unknown.png', 'f5ca38f748a1d6eaf726b8a42fb575c3c71f1864a8143301782de13da2d9202b'],
['https://cdn.discordapp.com/attachments/983923226193301524/993333709497446520/unknown.png', 'ef2d127de37b942baad06145e54b0c619a1f22327b2ebbcfbec78f5564afe39d'],
['https://cdn.discordapp.com/attachments/983923226193301524/993334609033039972/unknown.png', '19581e27de7ced00ff1ce50b2047e7a567c76b1cbaebabe5ef03f7c3017bb5b7'],
['https://cdn.discordapp.com/attachments/983923226193301524/993334809642418206/unknown.png', 'f74efabef12ea619e30b79bddef89cffa9dda494761681ca862cff2871a85980'],
['https://cdn.discordapp.com/attachments/983923226193301524/993335006275567666/unknown.png', 'e078af3026edb42cc26b32784baa142a79970078f7ac58f8c7b74115f4f7fb60'],
['https://cdn.discordapp.com/attachments/983923226193301524/993335443603071087/unknown.png', '59e19706d51d39f66711c2653cd7eb1291c94d9b55eb14bda74ce4dc636d015a'],
['https://cdn.discordapp.com/attachments/983923226193301524/993335611832414250/unknown.png', '4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce'],
['https://cdn.discordapp.com/attachments/983923226193301524/993335749598515320/unknown.png', '51d089cdaf0c968c94b80671489d22b6f79b1c57de80df880b008e9b37b49788'],
['https://cdn.discordapp.com/attachments/983923226193301524/1013325212500107324/unknown.png', '66849e29a8eb896b7e92bd83752a609d9b7106f7755561464df37c0bd9249781'],
['https://cdn.discordapp.com/attachments/983923226193301524/1013325591715512421/unknown.png', 'aea92132c4cbeb263e6ac2bf6c183b5d81737f179f21efdc5863739672f0f470'],
['https://cdn.discordapp.com/attachments/983923226193301524/1013325809970315325/unknown.png', '1bea20e1df19b12013976de2b5e0e3d1fb4ba088b59fe53642c324298b21ffd9'],
['https://cdn.discordapp.com/attachments/983923226193301524/1013325951523897394/unknown.png', '8a9a02d73aeefd97306a08c30969a9e8d5ef03960978a1c5db4447558d40f689'],
['https://cdn.discordapp.com/attachments/983923226193301524/1057201679843475526/image.png', 'c2356069e9d1e79ca924378153cfbbfb4d4416b1f99d41a2940bfdb66c5319db'],
['https://cdn.discordapp.com/attachments/983923226193301524/1057202161194369044/image.png', '35135aaa6cc23891b40cb3f378c53a17a1127210ce60e125ccf03efcfdaec458'],
['https://cdn.discordapp.com/attachments/983923226193301524/1057202595896246402/image.png', '624b60c58c9d8bfb6ff1886c2fd605d2adeb6ea4da576068201b6c6958ce93f4'],
['https://cdn.discordapp.com/attachments/983923226193301524/1057202817594576986/image.png', '8527a891e224136950ff32ca212b45bc93f69fbb801c3b1ebedac52775f99e61'],
['https://cdn.discordapp.com/attachments/983923226193301524/1057202986146869248/image.png', '2c624232cdd221771294dfbb310aca000a0df6ac8b66b696d90ef06fdefb64a3'],
['https://cdn.discordapp.com/attachments/983923226193301524/1057203194972880926/image.png', 'f5ca38f748a1d6eaf726b8a42fb575c3c71f1864a8143301782de13da2d9202b']
];
let buzzed = false;
let buzzleft = 5;
let problem = problems[0];
let startTime = 0;
let totalTime = 0;
let current = 0;
let data = {};
let probNum = 1;
let probNums = [];
for (let i=0; i<problems.length; i++) {
probNums.push(i);
}
let chosenProbs = getRandom(probNums,5);
let oppData = {"1":[chosenProbs[0],45000,true],"2":[chosenProbs[1],45000,true],"3":[chosenProbs[2],45000,true],"4":[chosenProbs[3],45000,true],"5":[chosenProbs[4],45000,true]};
let score = 0;
let oppScore = 0;
function getRandom(arr, n) {
var result = new Array(n),
len = arr.length,
taken = new Array(len);
if (n > len)
throw new RangeError("getRandom: more elements taken than available");
while (n--) {
var x = Math.floor(Math.random() * len);
result[n] = arr[x in taken ? taken[x] : x];
taken[x] = --len in taken ? taken[len] : len;
}
return result;
}
function start() {
current = oppData[String(probNum)][0];
problem = problems[current];
document.getElementById("problem").src = problem[0];
let d = new Date();
startTime = d.getTime();
document.getElementById("startbutton").disabled = true;
document.getElementById("importbutton").disabled = true;
document.getElementById("buzzbutton").disabled = false;
document.getElementById("result").innerHTML = "Problem is flashed on the screen.";
document.getElementById("answer").disabled = true;
document.getElementById("answer").value = "";
setTimeout(oppBuzz,oppData[String(probNum)][1],probNum);
}
function oppBuzz(oldProb) {
if (buzzed == false && oldProb == probNum) {
if (oppData[String(probNum)][2] == true) {
oppScore += 1;
document.getElementById("result").innerHTML = "The opponent got it right.";
document.getElementById("score").innerHTML = String(score) + " you - " + String(oppScore) + " opponent";
} else {
score += 1;
document.getElementById("result").innerHTML = "The opponent got it wrong.";
document.getElementById("score").innerHTML = String(score) + " you - " + String(oppScore) + " opponent";
}
data[probNum] = [current,totalTime,false]
document.getElementById("startbutton").disabled = false;
document.getElementById("buzzbutton").disabled = true;
document.getElementById("answer").disabled = true;
buzzleft = 5;
buzzed = false;
probNum += 1;
if (probNum == 6) {
document.getElementById("tocopy").style.display = "";
document.getElementById("tocopy").innerHTML = "<b>Congratulations, you finished the game!</b> Copy this and send it to jatloe (this is your encrypted countdown data):<br> " + btoa(JSON.stringify(data));
}
}
}
function buzz() {
if (document.getElementById("buzzbutton").disabled == false && !buzzed) {
document.getElementById("buzzbutton").disabled = true;
document.getElementById("answer").disabled = false;
document.getElementById("answer").focus();
buzzed = true;
buzzTimeUpdate();
let d = new Date();
totalTime = d.getTime()-startTime;
}
}
function importOpponent() {
oppData = JSON.parse(atob(prompt("Please enter opponent data here:")));
}
function buzzTimeUpdate() {
if (buzzleft == 0) {
closeBuzz();
} else {
setTimeout(buzzTimeUpdate,1000);
buzzleft -= 1;
document.getElementById("result").innerHTML = String(buzzleft) + " seconds left";
}
}
function closeBuzz() {
document.getElementById("buzzbutton").disabled = true;
document.getElementById("answer").disabled = true;
if (sha256(document.getElementById("answer").value) == problem[1]) {
document.getElementById("result").innerHTML = "Correct! " + String(totalTime/1000) + " seconds";
data[probNum] = [current,totalTime,true]
score += 1;
document.getElementById("score").innerHTML = String(score) + " you - " + String(oppScore) + " opponent";
} else {
document.getElementById("result").innerHTML = "Incorrect.";
data[probNum] = [current,totalTime,false]
oppScore += 1;
document.getElementById("score").innerHTML = String(score) + " you - " + String(oppScore) + " opponent";
}
document.getElementById("startbutton").disabled = false;
buzzleft = 5;
buzzed = false;
probNum += 1;
if (probNum == 6) {
document.getElementById("tocopy").style.display = "";
document.getElementById("tocopy").innerHTML = "<b>Congratulations, you finished the game!</b> Copy this and send it to jatloe (this is your encrypted countdown data):<br> " + btoa(JSON.stringify(data));
}
}
document.onkeyup = function(e) {
if (e.which == 66) {
buzz();
}
};
// Get the modal
var modal = document.getElementById("myModal");
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</html>