-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
571 lines (508 loc) · 21.1 KB
/
index.html
File metadata and controls
571 lines (508 loc) · 21.1 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chess Analysis</title>
<link rel="icon" href="img/chesspieces/wikipedia/bK.png">
<link rel="stylesheet" href="https://unpkg.com/@chrisoakman/chessboardjs@1.0.0/dist/chessboard-1.0.0.min.css" integrity="sha384-q94+BZtLrkL1/ohfjR8c6L+A6qzNH9R2hBLwyoAfu3i/WCvQjzL2RQJ3uNHDISdU" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://unpkg.com/@chrisoakman/chessboardjs@1.0.0/dist/chessboard-1.0.0.min.js" integrity="sha384-8Vi8VHwn3vjQ9eUHUxex3JSN/NFqUg3QbPyX8kWyb93+8AC/pPWTzj+nHtbC5bxD" crossorigin="anonymous"></script>
<script src="js/chess.js"></script>
<script src="js/script.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<link rel="stylesheet" href="css/style.css">
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/8.2.3/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.3/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.3/firebase-firestore.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/8.2.3/firebase-analytics.js"></script>
<script>
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
var firebaseConfig = {
apiKey: "AIzaSyCb2fJLCp_BKBmrxOlPws-C5AEsANFOtuA",
authDomain: "chessanalysis-67912.firebaseapp.com",
projectId: "chessanalysis-67912",
storageBucket: "chessanalysis-67912.appspot.com",
messagingSenderId: "642735496796",
appId: "1:642735496796:web:ff384787fae13521d25099",
measurementId: "G-TYESDK0LSH"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
<script src="app.js" defer></script>
</head>
<body>
<style>
.container {
height: 50px;
position: relative;
padding: 2em;
margin-top: 2em;
}
.center {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
</style>
<nav class="navbar sticky-top navbar-custom">
<ul>
<!--<li><a href="" data-toggle="modal" data-target="#loginModal">Login</a></li>-->
<li><a href="" data-toggle="modal" data-target="#instructionsModal">Instructions</a></li>
<li><a href="#" onclick="darkMode()">Dark Mode</a></li>
</ul>
</nav>
<div class="modal fade" id="instructionsModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Instructions</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>1. Set your timer to your preferred duration.</p>
<p>2. Observe a random position for that duration.</p>
<p>3. Try to place the pieces back on the board to match the original position.</p>
<p>4. Repeat as much as you want, and go for a really high streak! Good luck!</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!--
<div id="loginModal" class="modal fade">
<div class="modal-dialog modal-login">
<div class="modal-content">
<form action="/examples/actions/confirmation.php" method="post">
<div class="modal-header">
<h4 class="modal-title">Login</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" required="required" style="width: 80%">
</div>
<div class="form-group">
<div class="clearfix">
<label>Password</label>
<a href="#" class="float-right text-muted"><small style="color: var(--text)">Forgot?</small></a>
</div>
<input type="password" class="form-control" required="required" style="width: 80%">
</div>
</div>
<div class="modal-footer justify-content-between">
<label class="form-check-label" style="color:black"><input type="checkbox"> Remember me</label>
<input type="submit" class="btn btn-primary" value="Login">
</div>
</form>
</div>
</div>
</div>
-->
<div class="modal fade" id="timerModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Timer</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="message-text" class="col-form-label">Desired time (in seconds):</label>
<textarea class="form-control" id="timerMessageText"></textarea>
</div>
<div class="form-group">
<label for="message-text" class="col-form-label">Quick Options:</label>
<button type="button" class="btn btn-primary" onclick="thirtyTimer()" data-dismiss="modal">00:30</button>
<button type="button" class="btn btn-primary" onclick="sixtyTimer()" data-dismiss="modal">1:00</button>
<button type="button" class="btn btn-primary" onclick="oneTwentyTimer()" data-dismiss="modal">2:00</button>
<button type="button" class="btn btn-primary" onclick="threeHundredTimer()" data-dismiss="modal">5:00</button>
<button type="button" class="btn btn-primary" onclick="sixHundredTimer()" data-dismiss="modal">10:00</button>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" onclick="customSetTimer()" data-dismiss="modal">Set</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="howCloseModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Incorrect</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p id="howCloseText"></p>
</div>
<div class="modal-footer">
<input type="checkbox" id="howCloseCheckbox" name="showCheckbox">
<label id="checkBoxText" for="showCheckbox">Don't show again</label>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col">
</div>
<div class="col-lg-6">
<div id="startBoard" style="width: 75%; max-width: 100%;margin: auto; padding: 1em"></div>
<div id="solveBoard" style="width: 65%; max-width: 100%; display: none; margin: auto"></div>
</div>
<div class="col-sm align-self-center">
<div class="text-center">
<button id="startButton" class="button" style="margin: auto" onclick="runTimer()">Start</button>
<h1 id="timer" data-toggle="modal" data-target="#timerModal">01:00</h1>
<div id="solveDiv" style="display:none">
<button id="checkButton" class="button" onclick="checkAnswer()" style="display: inline">Check</button>
<br><br>
<button id="solutionButton" class="button" onclick="showSolution()" style="display: inline; pointer-events: none">See Solution</button>
<br><br>
<button id="resetButton" class="button" onclick="resetBoard()" style="display: inline">Reset</button>
</div>
<div>
<i id="streakIcon" class="fas fa-fire"></i>
<h1 style="display: inline" id="streakText">0</h1>
<i class="fas fa-grip-lines-vertical"></i>
<i id="correctIcon" class="fas fa-check-circle"></i>
<h1 style="display: inline" id="correctText">0</h1>
<i class="fas fa-grip-lines-vertical"></i>
<i id="wrongIcon" class="fas fa-times-circle"></i>
<h1 style="display: inline" id="wrongText">0</h1>
</div>
</div>
</div>
</div>
</div>
<script>
function darkMode(){
var element = document.body;
element.classList.toggle("theme-switch");
}
const chess = new Chess();
var config = {
draggable: true,
dropOffBoard: 'trash',
sparePieces: true
}
var board = Chessboard('startBoard', 'clear');
var solutionBoard = Chessboard('solveBoard', config);
var games = [
"br3r1k/p5b1/8/1p2pPB1/2p5/P6P/2B3PK/1R3N2",
"br1q1rk1/p3p1bp/6p1/1p1n2B1/2pPB3/P1P4P/2Q2PP1/1R1R1NK1",
"r3r3/1p1n2bk/1n1pb1pp/pPp2p2/P1P1P2q/R3BN1P/5PP1/1NQ1RBK1",
"7q/pppb1pk1/3p1ppr/2bPpP2/2B1P1Q1/2P2N2/P5PP/4R2K",
"2k5/p1q1bp2/Q1p1p2p/4P1pP/6P1/P7/KPP2P2/3R4",
"2r1r1k1/2p3pp/1pb5/2p1b1P1/5B2/p1P2PKP/PP1R4/2N2R2",
"6kr/pp4p1/1b4q1/1Pp1p3/2PnP3/4B1Pp/P6P/RQ4K1",
"8/3n1Bpk/r2b3p/2p5/2R3PP/4B3/1PK2P2/8",
"2R5/4rk1p/1p1ppb2/1P2Np2/1P2n1p1/4P1P1/rB3P1P/3RN1K1",
"3r2k1/p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qbp/1Np1b3/p1Ppp1p1/4np2/BP5P/P3BPP1/1RQ2RK1",
"4rk2/pp1R2pp/2p1n2r/4Pq2/2B1R3/5P1P/PP1Q2PK/8",
"r1r5/pq1bpnkp/1p1p2p1/3P4/3B1P2/1P5P/P2QB1P1/2R2RK1",
"2r2r2/6k1/p2R1np1/1p2p3/6N1/1Pn4P/P1P3B1/2R3K1",
"2nr4/1p1r1pkp/4p1p1/2q5/2Pp4/1P3B1P/P2RQPP1/3R2K1"
];
var numCorrect = 0;
var numWrong = 0;
var numStreak = 0;
var numOff = 0;
var interval = 1000; // ms
var expected = Date.now() + interval;
setTimeout(step, interval);
var startTime = 60;
var oldStartTime = 0;
var timerIsRunning = false;
function runTimer(){
document.getElementById("startButton").style.display = "none";
document.getElementById("timer").style.pointerEvents = "none";
timerIsRunning = true;
var game = games[Math.floor(Math.random() * games.length)];
board.position(game);
}
function thirtyTimer(){
startTime = 30;
changeTimer();
}
function sixtyTimer(){
startTime = 60;
changeTimer();
}
function oneTwentyTimer(){
startTime = 120;
changeTimer();
}
function threeHundredTimer(){
startTime = 300;
changeTimer();
}
function sixHundredTimer(){
startTime = 600;
changeTimer();
}
function customSetTimer(){
startTime = $("#timerMessageText").val();
if(isNaN(startTime) || startTime < 0){
alert("Not a valid number. Try again");
}
else{
changeTimer();
}
}
function changeTimer(){
oldStartTime = startTime;
if(startTime != null){
if(startTime < 10){
document.getElementById("timer").innerHTML = "00:0" + startTime;
}
else if(startTime >= 60){
var min = Math.floor(startTime / 60);
var seconds = startTime % 60;
if(min >= 10){
if(seconds < 10){
document.getElementById("timer").innerHTML = min + ":0" + seconds;
}
else{
document.getElementById("timer").innerHTML = min + ":" + seconds;
}
}
else if(seconds < 10){
document.getElementById("timer").innerHTML = "0" + min + ":0" + seconds;
}
else{
document.getElementById("timer").innerHTML = "0" + min + ":" + seconds;
}
}
else{
document.getElementById("timer").innerHTML = "00:" + startTime;
}
}
}
function howClose(){
if(board.fen() === solutionBoard.fen()){
}
else{
var correctArr = board.fen().split("/");
var guessArr = solutionBoard.fen().split("/");
console.log(correctArr);
console.log(guessArr);
for(var i = 0; i < correctArr.length; i++){
if(correctArr[i] === guessArr[i]){
}
else{
var correctStr = correctArr[i];
var guessStr = guessArr[i];
var correctPieceStr = "";
var guessPieceStr = "";
for(var j = 0; j < correctStr.length; j++){
var c = correctStr.charAt(j);
if(isNaN(c)){
correctPieceStr += c;
}
else{
for(var k = 0; k < c; k++){
correctPieceStr += "_";
}
}
}
for(var l = 0; l < guessStr.length; l++){
var c = guessStr.charAt(l);
if(isNaN(c)){
guessPieceStr += c;
}
else{
for(var m = 0; m < c; m++){
guessPieceStr += "_";
}
}
}
for(var n = 0; n < 8; n++){
if(!(guessPieceStr.charAt(n) === correctPieceStr.charAt(n))){
numOff++;
}
}
}
}
}
}
function checkAnswer(){
document.getElementById("solutionButton").style.pointerEvents = "auto";
document.getElementById("checkButton").style.pointerEvents = "none";
if(board.fen() === solutionBoard.fen()){
numCorrect++;
numStreak++;
document.getElementById("correctText").innerHTML = numCorrect;
document.getElementById("streakText").innerHTML = numStreak;
}
else{
numWrong++;
numStreak = 0;
document.getElementById("wrongText").innerHTML = numWrong;
document.getElementById("streakText").innerHTML = numStreak;
howClose();
if(!($("#howCloseCheckbox").is(":checked"))){
document.getElementById("howCloseText").innerHTML = "You were " + numOff + " pieces off.";
$('#howCloseModal').modal('toggle');
}
}
}
function showSolution(){
document.getElementById("startBoard").style.display= "block";
document.getElementById("solveBoard").style.display = "none";
}
function resetBoard(){
numOff = 0;
board.clear();
solutionBoard.clear();
document.getElementById("startBoard").style.display= "block";
document.getElementById("solveBoard").style.display = "none";
document.getElementById("startButton").style.display = "block";
document.getElementById("timer").style.pointerEvents = "auto";
document.getElementById("timer").style.display = "block";
document.getElementById("solveDiv").style.display = "none";
document.getElementById("solutionButton").style.pointerEvents = "none";
document.getElementById("checkButton").style.pointerEvents = "auto";
if(oldStartTime < 10){
document.getElementById("timer").innerHTML = "00:0" + oldStartTime;
}
else if(oldStartTime >= 60){
var min = Math.floor(oldStartTime / 60);
var seconds = oldStartTime % 60;
if(min >= 10){
if(seconds < 10){
document.getElementById("timer").innerHTML = min + ":0" + seconds;
}
else{
document.getElementById("timer").innerHTML = min + ":" + seconds;
}
}
else if(seconds < 10){
document.getElementById("timer").innerHTML = "0" + min + ":0" + seconds;
}
else{
document.getElementById("timer").innerHTML = "0" + min + ":" + seconds;
}
}
else{
document.getElementById("timer").innerHTML = "00:" + oldStartTime;
}
}
function step() {
var dt = Date.now() - expected; // the drift (positive for overshooting)
if (dt > interval) {
// something really bad happened. Maybe the browser (tab) was inactive?
// possibly special handling to avoid futile "catch up" run
}
if(timerIsRunning){
if(startTime < 0){
document.getElementById("startBoard").style.display= "none";
document.getElementById("solveBoard").style.display = "block";
document.getElementById("timer").style.display = "none";
document.getElementById("solveDiv").style.display = "block";
timerIsRunning = false;
startTime = oldStartTime;
}
else{
if(startTime < 10){
document.getElementById("timer").innerHTML = "00:0" + startTime;
}
else if(startTime >= 60){
var min = Math.floor(startTime / 60);
var seconds = startTime % 60;
if(min >= 10){
if(seconds < 10){
document.getElementById("timer").innerHTML = min + ":0" + seconds;
}
else{
document.getElementById("timer").innerHTML = min + ":" + seconds;
}
}
else if(seconds < 10){
document.getElementById("timer").innerHTML = "0" + min + ":0" + seconds;
}
else{
document.getElementById("timer").innerHTML = "0" + min + ":" + seconds;
}
}
else{
document.getElementById("timer").innerHTML = "00:" + startTime;
}
startTime--;
}
}
expected += interval;
setTimeout(step, Math.max(0, interval - dt)); // take into account drift
}
</script>
</body>
</html>