-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChessLoops.htm
More file actions
967 lines (892 loc) · 44.4 KB
/
Copy pathChessLoops.htm
File metadata and controls
967 lines (892 loc) · 44.4 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
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
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chess Repertoire Trainer</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chess.js/0.10.3/chess.min.js"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');
body {
font-family: 'Inter', sans-serif;
background-color: #0f172a;
color: #f8fafc;
}
.chess-board {
display: grid;
grid-template-columns: repeat(8, 1fr);
grid-template-rows: repeat(8, 1fr);
width: 100%;
aspect-ratio: 1 / 1;
border: 4px solid #334155;
user-select: none;
position: relative;
}
.chess-board.flipped { transform: rotate(180deg); }
.chess-board.flipped .piece { transform: rotate(180deg); }
.square {
display: flex;
align-items: center;
justify-content: center;
position: relative;
cursor: pointer;
}
.square.light { background-color: #e2e8f0; }
.square.dark { background-color: #94a3b8; }
.square.last-move { background-color: rgba(253, 224, 71, 0.6) !important; }
.square.selected { background-color: rgba(59, 130, 246, 0.6) !important; }
.square.valid-target::after {
content: '';
width: 25%;
height: 25%;
background-color: rgba(0, 0, 0, 0.1);
border-radius: 50%;
}
.piece {
width: 90%;
height: 90%;
z-index: 10;
pointer-events: none;
}
.feedback-container {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
pointer-events: none;
z-index: 100;
opacity: 0;
}
.feedback-icon {
width: 80px;
height: 80px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
animation: pop-feedback 0.6s ease-out forwards;
}
.icon-success { background-color: #22c55e; box-shadow: 0 0 20px rgba(34, 197, 94, 0.5); }
.icon-error { background-color: #ef4444; box-shadow: 0 0 20px rgba(239, 68, 68, 0.5); }
@keyframes pop-feedback {
0% { transform: scale(0.5); opacity: 0; }
30% { transform: scale(1.1); opacity: 1; }
70% { transform: scale(1); opacity: 1; }
100% { transform: scale(1); opacity: 0; }
}
.checkmark {
width: 20px;
height: 40px;
border-bottom: 6px solid white;
border-right: 6px solid white;
transform: rotate(45deg);
margin-bottom: 5px;
}
.cross { position: relative; width: 40px; height: 40px; }
.cross::before, .cross::after {
content: '';
position: absolute;
top: 18px;
left: 0;
width: 40px;
height: 6px;
background-color: white;
border-radius: 3px;
}
.cross::before { transform: rotate(45deg); }
.cross::after { transform: rotate(-45deg); }
.pgn-input { scrollbar-width: thin; scrollbar-color: #475569 #1e293b; }
.custom-shadow { box-shadow: 0 10px 25px -5px rgba(0,0,0,0.3), 0 8px 10px -6px rgba(0,0,0,0.3); }
/* Modal */
#openingsModal {
display: none;
position: fixed;
inset: 0;
z-index: 1000;
align-items: center;
justify-content: center;
background: rgba(0,0,0,0.7);
backdrop-filter: blur(4px);
padding: 1rem;
}
#openingsModal.open { display: flex; }
.modal-box {
background: #1e293b;
border: 1px solid #334155;
border-radius: 1rem;
width: 100%;
max-width: 680px;
max-height: 85vh;
display: flex;
flex-direction: column;
box-shadow: 0 25px 60px rgba(0,0,0,0.5);
animation: modal-in 0.2s ease-out;
}
@keyframes modal-in {
from { opacity: 0; transform: scale(0.95) translateY(10px); }
to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 1.25rem 1.5rem;
border-bottom: 1px solid #334155;
flex-shrink: 0;
}
.modal-body {
overflow-y: auto;
padding: 1.25rem 1.5rem;
scrollbar-width: thin;
scrollbar-color: #475569 #1e293b;
}
/* Tab bar */
.tab-bar {
display: flex;
gap: 0.5rem;
margin-bottom: 1.25rem;
background: #0f172a;
border-radius: 0.5rem;
padding: 0.25rem;
flex-shrink: 0;
}
.tab-btn {
flex: 1;
padding: 0.5rem 1rem;
border-radius: 0.4rem;
font-size: 0.875rem;
font-weight: 600;
cursor: pointer;
border: none;
transition: all 0.15s;
color: #94a3b8;
background: transparent;
}
.tab-btn.active {
background: #3b82f6;
color: white;
}
/* Opening cards */
.opening-category { margin-bottom: 1.25rem; }
.opening-category h3 {
font-size: 0.65rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.1em;
color: #64748b;
margin-bottom: 0.5rem;
}
.openings-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
gap: 0.5rem;
}
.opening-card {
background: #0f172a;
border: 1px solid #334155;
border-radius: 0.5rem;
padding: 0.75rem;
cursor: pointer;
transition: all 0.15s;
text-align: left;
}
.opening-card:hover {
border-color: #3b82f6;
background: #1e3a5f;
}
.opening-card.selected {
border-color: #3b82f6;
background: #1e3a5f;
box-shadow: 0 0 0 2px rgba(59,130,246,0.3);
}
.opening-card .card-name {
font-size: 0.85rem;
font-weight: 600;
color: #f1f5f9;
margin-bottom: 0.2rem;
}
.opening-card .card-lines {
font-size: 0.7rem;
color: #64748b;
}
.opening-card .card-tag {
display: inline-block;
font-size: 0.6rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.05em;
padding: 0.1rem 0.35rem;
border-radius: 9999px;
margin-top: 0.4rem;
}
.tag-e4 { background: #7c3aed22; color: #a78bfa; border: 1px solid #7c3aed44; }
.tag-d4 { background: #0369a122; color: #38bdf8; border: 1px solid #0369a144; }
.tag-other { background: #05966922; color: #34d399; border: 1px solid #05966944; }
.modal-footer {
padding: 1rem 1.5rem;
border-top: 1px solid #334155;
display: flex;
gap: 0.75rem;
justify-content: flex-end;
flex-shrink: 0;
}
</style>
</head>
<body class="min-h-screen flex flex-col items-center p-4 md:p-8">
<!-- ========== POPULAR OPENINGS MODAL ========== -->
<div id="openingsModal">
<div class="modal-box">
<div class="modal-header">
<div>
<h2 class="text-lg font-bold">Popular Openings</h2>
<p class="text-xs text-slate-400 mt-0.5">Select an opening to load its lines into the trainer</p>
</div>
<button onclick="closeModal()" class="text-slate-400 hover:text-white text-2xl leading-none">×</button>
</div>
<!-- Tab bar inside modal body header -->
<div class="px-6 pt-4 flex-shrink-0">
<div class="tab-bar">
<button class="tab-btn active" id="tabWhite" onclick="switchTab('white')">♔ As White</button>
<button class="tab-btn" id="tabBlack" onclick="switchTab('black')">♚ As Black</button>
</div>
</div>
<div class="modal-body" id="modalBody"></div>
<div class="modal-footer">
<button onclick="closeModal()" class="px-4 py-2 rounded-lg text-sm border border-slate-600 text-slate-300 hover:bg-slate-700 transition-colors">Cancel</button>
<button onclick="loadSelectedOpening()" class="px-5 py-2 rounded-lg text-sm font-semibold bg-blue-600 hover:bg-blue-500 text-white transition-colors">Load Lines</button>
</div>
</div>
</div>
<!-- ========== MAIN APP ========== -->
<div class="max-w-6xl w-full grid grid-cols-1 lg:grid-cols-12 gap-8">
<!-- Sidebar -->
<div class="lg:col-span-4 flex flex-col gap-6">
<div class="bg-slate-800 p-6 rounded-xl border border-slate-700 custom-shadow">
<h2 class="text-xl font-bold mb-4">Line Setup</h2>
<p class="text-sm text-slate-400 mb-4">Paste multiple PGN lines below.</p>
<textarea
id="pgnInput"
class="w-full h-48 bg-slate-900 border border-slate-600 rounded-lg p-3 text-sm font-mono focus:ring-2 focus:ring-blue-500 focus:outline-none pgn-input"
placeholder="Paste lines here..."
></textarea>
<div class="flex gap-2 mt-4">
<button
onclick="openModal()"
class="flex-1 bg-slate-700 hover:bg-slate-600 border border-slate-500 text-white font-semibold py-2 rounded-lg transition-all text-sm flex items-center justify-center gap-2"
>
<span>♟</span> Popular Openings
</button>
<button
onclick="loadLines()"
class="flex-1 bg-blue-600 hover:bg-blue-500 text-white font-semibold py-2 rounded-lg transition-all text-sm"
>
Load Repertoire
</button>
</div>
</div>
<div id="lineListContainer" class="bg-slate-800 p-6 rounded-xl border border-slate-700 custom-shadow hidden">
<h2 class="text-xl font-bold mb-4">Select Line</h2>
<div id="lineList" class="flex flex-col gap-2 max-h-64 overflow-y-auto pr-2"></div>
</div>
</div>
<!-- Board -->
<div class="lg:col-span-5 flex flex-col items-center">
<div class="mb-6 flex bg-slate-800 p-1 rounded-lg border border-slate-700">
<button
id="sideWhite"
onclick="setUserSide('w')"
class="px-6 py-2 rounded-md text-sm font-semibold transition-all bg-blue-600 text-white"
>
Play as White
</button>
<button
id="sideBlack"
onclick="setUserSide('b')"
class="px-6 py-2 rounded-md text-sm font-semibold transition-all text-slate-400 hover:text-white"
>
Play as Black
</button>
</div>
<div class="relative w-full max-w-[500px]">
<div id="board" class="chess-board rounded shadow-2xl overflow-hidden"></div>
<div id="feedbackSuccess" class="feedback-container">
<div class="feedback-icon icon-success"><div class="checkmark"></div></div>
</div>
<div id="feedbackError" class="feedback-container">
<div class="feedback-icon icon-error"><div class="cross"></div></div>
</div>
</div>
<div class="mt-6 w-full max-w-[500px] flex justify-between items-center bg-slate-800 p-4 rounded-lg border border-slate-700">
<div id="statusLabel" class="text-lg font-medium text-slate-300">Awaiting Input</div>
<div id="moveCounter" class="text-blue-400 font-bold">0 / 0</div>
</div>
</div>
<!-- Move History -->
<div class="lg:col-span-3">
<div class="bg-slate-800 p-6 rounded-xl border border-slate-700 custom-shadow h-full">
<h2 class="text-xl font-bold mb-4">Move History</h2>
<div id="moveHistory" class="flex flex-wrap gap-2 text-sm">
<span class="text-slate-500 italic">No line active</span>
</div>
<div class="mt-8 border-t border-slate-700 pt-6">
<h3 class="text-xs font-semibold text-slate-500 uppercase tracking-widest mb-4">Settings</h3>
<div class="flex items-center justify-between">
<span class="text-sm">Flip Board</span>
<button
onclick="toggleFlip()"
class="bg-slate-700 px-4 py-1 rounded-md text-sm border border-slate-600 hover:bg-slate-600 transition-colors"
>
Rotate
</button>
</div>
<button
onclick="resetCurrentLine()"
class="mt-8 w-full border border-slate-600 hover:bg-slate-700 text-slate-300 py-2 rounded-lg text-sm transition-colors"
>
Reset Line
</button>
</div>
</div>
</div>
</div>
<script>
// ============================================================
// OPENINGS DATABASE
// ============================================================
const OPENINGS = {
white: [
{
category: "1. e4 Openings",
items: [
{
name: "Italian Game",
tag: "e4",
lines: [
"1. e4 e5 2. Nf3 Nc6 3. Bc4 Bc5 4. c3 Nf6 5. d4 exd4 6. cxd4 Bb4+ 7. Bd2 Bxd2+ 8. Nbxd2 *",
"1. e4 e5 2. Nf3 Nc6 3. Bc4 Nf6 4. d3 Bc5 5. O-O O-O 6. c3 d6 7. Bb3 a6 *",
"1. e4 e5 2. Nf3 Nc6 3. Bc4 Bc5 4. O-O Nf6 5. d3 O-O 6. c3 d6 7. Re1 a6 *"
]
},
{
name: "Ruy Lopez",
tag: "e4",
lines: [
"1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Ba4 Nf6 5. O-O Be7 6. Re1 b5 7. Bb3 d6 8. c3 O-O 9. h3 *",
"1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Ba4 Nf6 5. O-O Nxe4 6. d4 b5 7. Bb3 d5 8. dxe5 Be6 *",
"1. e4 e5 2. Nf3 Nc6 3. Bb5 Nf6 4. O-O Nxe4 5. d4 Nd6 6. Bxc6 dxc6 7. dxe5 Nf5 8. Qxd8+ *"
]
},
{
name: "King's Gambit",
tag: "e4",
lines: [
"1. e4 e5 2. f4 exf4 3. Nf3 d6 4. Bc4 h6 5. d4 g5 6. O-O Bg7 7. c3 *",
"1. e4 e5 2. f4 exf4 3. Nf3 g5 4. Bc4 g4 5. O-O gxf3 6. Qxf3 Qf6 7. e5 Qxe5 *",
"1. e4 e5 2. f4 d5 3. exd5 e4 4. d3 Nf6 5. dxe4 Nxe4 6. Nf3 Bc5 *"
]
},
{
name: "Scotch Game",
tag: "e4",
lines: [
"1. e4 e5 2. Nf3 Nc6 3. d4 exd4 4. Nxd4 Nf6 5. Nxc6 bxc6 6. e5 Qe7 7. Qe2 Nd5 8. c4 *",
"1. e4 e5 2. Nf3 Nc6 3. d4 exd4 4. Nxd4 Bc5 5. Be3 Qf6 6. c3 Nge7 7. Bc4 *",
"1. e4 e5 2. Nf3 Nc6 3. d4 exd4 4. Nxd4 d6 5. Nc3 Nf6 6. g3 Be7 7. Bg2 O-O *"
]
},
{
name: "Vienna Game",
tag: "e4",
lines: [
"1. e4 e5 2. Nc3 Nf6 3. f4 d5 4. fxe5 Nxe4 5. Nf3 Nc6 6. d4 *",
"1. e4 e5 2. Nc3 Nc6 3. Bc4 Bc5 4. Qg4 Qf6 5. Nd5 Qxf2+ 6. Kd1 *",
"1. e4 e5 2. Nc3 Nf6 3. g3 d5 4. exd5 Nxd5 5. Bg2 Nxc3 6. bxc3 Bd6 *"
]
}
]
},
{
category: "1. d4 Openings",
items: [
{
name: "London System",
tag: "d4",
lines: [
"1. d4 d5 2. Bf4 Nf6 3. e3 e6 4. Nf3 c5 5. c3 Nc6 6. Bd3 Bd6 7. Bxd6 Qxd6 8. Nbd2 *",
"1. d4 Nf6 2. Bf4 d5 3. e3 e6 4. Nf3 Bd6 5. Bg3 O-O 6. Bd3 c5 7. c3 Nc6 *",
"1. d4 d5 2. Bf4 c5 3. e3 Nc6 4. Nf3 Nf6 5. c3 e6 6. Bd3 Bd6 7. Bxd6 Qxd6 *",
"1. d4 Nf6 2. Bf4 g6 3. e3 Bg7 4. Nf3 d6 5. h3 O-O 6. Be2 c5 7. c3 *"
]
},
{
name: "Queen's Gambit",
tag: "d4",
lines: [
"1. d4 d5 2. c4 e6 3. Nc3 Nf6 4. Bg5 Be7 5. e3 O-O 6. Nf3 h6 7. Bh4 b6 *",
"1. d4 d5 2. c4 dxc4 3. e4 e5 4. Nf3 exd4 5. Bxc4 Nc6 6. O-O Bc5 *",
"1. d4 d5 2. c4 c6 3. Nf3 Nf6 4. Nc3 e6 5. e3 a6 6. b3 Bb4 7. Bd2 *"
]
},
{
name: "Catalan Opening",
tag: "d4",
lines: [
"1. d4 Nf6 2. c4 e6 3. g3 d5 4. Bg2 Be7 5. Nf3 O-O 6. O-O dxc4 7. Qc2 a6 8. Qxc4 *",
"1. d4 Nf6 2. c4 e6 3. g3 d5 4. Nf3 Be7 5. Bg2 O-O 6. O-O c6 7. Qc2 Nbd7 *",
"1. d4 d5 2. c4 e6 3. g3 Nf6 4. Bg2 dxc4 5. Nf3 Nc6 6. O-O Rb8 7. Qc2 *"
]
},
{
name: "King's Indian Attack",
tag: "other",
lines: [
"1. Nf3 d5 2. g3 Nf6 3. Bg2 e6 4. O-O Be7 5. d3 O-O 6. Nbd2 c5 7. e4 *",
"1. e4 c5 2. Nf3 e6 3. d3 Nc6 4. g3 Nf6 5. Bg2 Be7 6. O-O O-O 7. Nbd2 *",
"1. Nf3 Nf6 2. g3 g6 3. Bg2 Bg7 4. O-O O-O 5. d3 d6 6. Nbd2 Nbd7 7. e4 *"
]
},
{
name: "Colle System",
tag: "d4",
lines: [
"1. d4 d5 2. Nf3 Nf6 3. e3 e6 4. Bd3 c5 5. c3 Nc6 6. Nbd2 Bd6 7. O-O O-O *",
"1. d4 d5 2. Nf3 Nf6 3. e3 Bf5 4. Bd3 Bxd3 5. Qxd3 e6 6. O-O c5 7. c3 *",
"1. d4 Nf6 2. Nf3 d5 3. e3 e6 4. Bd3 Be7 5. O-O O-O 6. b3 b6 7. Bb2 *"
]
}
]
}
],
black: [
{
category: "Responses to 1. e4",
items: [
{
name: "Sicilian Defense",
tag: "e4",
lines: [
"1. e4 c5 2. Nf3 d6 3. d4 cxd4 4. Nxd4 Nf6 5. Nc3 a6 6. Be2 e5 7. Nb3 Be7 8. O-O O-O *",
"1. e4 c5 2. Nf3 Nc6 3. d4 cxd4 4. Nxd4 g6 5. Nc3 Bg7 6. Be3 Nf6 7. Bc4 O-O *",
"1. e4 c5 2. Nf3 e6 3. d4 cxd4 4. Nxd4 Nf6 5. Nc3 d6 6. g4 h6 7. g5 hxg5 *",
"1. e4 c5 2. c3 d5 3. exd5 Qxd5 4. d4 Nf6 5. Nf3 Bg4 6. dxc5 e6 7. Be2 *"
]
},
{
name: "French Defense",
tag: "e4",
lines: [
"1. e4 e6 2. d4 d5 3. Nc3 Bb4 4. e5 c5 5. a3 Bxc3+ 6. bxc3 Ne7 7. Qg4 cxd4 *",
"1. e4 e6 2. d4 d5 3. Nd2 Nf6 4. e5 Nfd7 5. Bd3 c5 6. c3 Nc6 7. Ne2 cxd4 *",
"1. e4 e6 2. d4 d5 3. e5 c5 4. c3 Nc6 5. Nf3 Bd7 6. Be2 Nge7 7. Na3 *"
]
},
{
name: "Caro-Kann Defense",
tag: "e4",
lines: [
"1. e4 c6 2. d4 d5 3. Nc3 dxe4 4. Nxe4 Bf5 5. Ng3 Bg6 6. h4 h6 7. Nf3 Nd7 *",
"1. e4 c6 2. d4 d5 3. e5 Bf5 4. Nf3 e6 5. Be2 Ne7 6. O-O c5 7. c3 *",
"1. e4 c6 2. c4 d5 3. exd5 cxd5 4. cxd5 Nf6 5. Nc3 g6 6. Nf3 Bg7 *"
]
},
{
name: "Pirc Defense",
tag: "e4",
lines: [
"1. e4 d6 2. d4 Nf6 3. Nc3 g6 4. Nf3 Bg7 5. Bc4 O-O 6. O-O Bg4 7. h3 Bxf3 8. Qxf3 Nc6 *",
"1. e4 d6 2. d4 Nf6 3. Nc3 g6 4. Bc4 Bg7 5. Nf3 O-O 6. O-O Bg4 7. h3 Bxf3 8. Qxf3 Nc6 *",
"1. e4 d6 2. d4 Nf6 3. Nc3 g6 4. f4 Bg7 5. Nf3 O-O 6. Bd3 Na6 7. O-O c5 *"
]
},
{
name: "Scandinavian Defense",
tag: "e4",
lines: [
"1. e4 d5 2. exd5 Qxd5 3. Nc3 Qa5 4. d4 Nf6 5. Nf3 Bf5 6. Bc4 e6 7. Bd2 Qb6 *",
"1. e4 d5 2. exd5 Nf6 3. d4 Nxd5 4. c4 Nb6 5. Nf3 g6 6. Nc3 Bg7 7. Be2 O-O *",
"1. e4 d5 2. exd5 Qxd5 3. Nc3 Qd8 4. d4 Nf6 5. Nf3 Bf5 6. Bc4 e6 *"
]
}
]
},
{
category: "Responses to 1. d4",
items: [
{
name: "King's Indian Defense",
tag: "d4",
lines: [
"1. d4 Nf6 2. c4 g6 3. Nc3 Bg7 4. e4 d6 5. Nf3 O-O 6. Be2 e5 7. O-O Nc6 8. d5 *",
"1. d4 Nf6 2. c4 g6 3. Nc3 Bg7 4. e4 d6 5. f3 O-O 6. Be3 c5 7. dxc5 dxc5 *",
"1. d4 Nf6 2. c4 g6 3. g3 Bg7 4. Bg2 d6 5. Nf3 O-O 6. Nc3 Nc6 7. O-O e5 *"
]
},
{
name: "Nimzo-Indian Defense",
tag: "d4",
lines: [
"1. d4 Nf6 2. c4 e6 3. Nc3 Bb4 4. Qc2 d5 5. cxd5 Qxd5 6. e3 O-O 7. a3 Bxc3+ *",
"1. d4 Nf6 2. c4 e6 3. Nc3 Bb4 4. e3 O-O 5. Bd3 d5 6. Nf3 c5 7. O-O Nc6 *",
"1. d4 Nf6 2. c4 e6 3. Nc3 Bb4 4. a3 Bxc3+ 5. bxc3 d6 6. Nf3 Qd7 7. e4 *"
]
},
{
name: "Grünfeld Defense",
tag: "d4",
lines: [
"1. d4 Nf6 2. c4 g6 3. Nc3 d5 4. cxd5 Nxd5 5. e4 Nxc3 6. bxc3 Bg7 7. Nf3 c5 8. Be3 *",
"1. d4 Nf6 2. c4 g6 3. Nc3 d5 4. Bg5 Ne4 5. Bh4 Nxc3 6. bxc3 dxc4 7. e3 *",
"1. d4 Nf6 2. c4 g6 3. g3 d5 4. Bg2 Bg7 5. Nf3 O-O 6. cxd5 Nxd5 7. O-O Nb6 *"
]
},
{
name: "Dutch Defense",
tag: "other",
lines: [
"1. d4 f5 2. g3 Nf6 3. Bg2 e6 4. Nf3 Be7 5. O-O O-O 6. c4 d6 7. Nc3 Ne4 *",
"1. d4 f5 2. c4 Nf6 3. g3 e6 4. Bg2 Be7 5. Nf3 O-O 6. O-O d5 7. b3 c6 *",
"1. d4 f5 2. Nf3 Nf6 3. g3 g6 4. Bg2 Bg7 5. O-O O-O 6. c4 d6 7. Nc3 *"
]
},
{
name: "Queen's Indian Defense",
tag: "d4",
lines: [
"1. d4 Nf6 2. c4 e6 3. Nf3 b6 4. g3 Bb7 5. Bg2 Be7 6. O-O O-O 7. Nc3 Ne4 *",
"1. d4 Nf6 2. c4 e6 3. Nf3 b6 4. e3 Bb7 5. Bd3 d5 6. O-O Be7 7. b3 O-O *",
"1. d4 Nf6 2. c4 e6 3. Nf3 b6 4. a3 Bb7 5. Nc3 d5 6. cxd5 Nxd5 7. e3 *"
]
}
]
}
]
};
// ============================================================
// MODAL STATE
// ============================================================
let currentTab = 'white';
let selectedOpening = null;
function openModal() {
document.getElementById('openingsModal').classList.add('open');
renderModal();
}
function closeModal() {
document.getElementById('openingsModal').classList.remove('open');
selectedOpening = null;
}
function switchTab(tab) {
currentTab = tab;
selectedOpening = null;
document.getElementById('tabWhite').classList.toggle('active', tab === 'white');
document.getElementById('tabBlack').classList.toggle('active', tab === 'black');
renderModal();
}
function renderModal() {
const body = document.getElementById('modalBody');
body.innerHTML = '';
const data = OPENINGS[currentTab];
data.forEach(category => {
const catDiv = document.createElement('div');
catDiv.className = 'opening-category';
catDiv.innerHTML = `<h3>${category.category}</h3>`;
const grid = document.createElement('div');
grid.className = 'openings-grid';
category.items.forEach(opening => {
const card = document.createElement('div');
card.className = 'opening-card';
if (selectedOpening && selectedOpening.name === opening.name) {
card.classList.add('selected');
}
const tagClass = opening.tag === 'e4' ? 'tag-e4' : opening.tag === 'd4' ? 'tag-d4' : 'tag-other';
card.innerHTML = `
<div class="card-name">${opening.name}</div>
<div class="card-lines">${opening.lines.length} line${opening.lines.length !== 1 ? 's' : ''}</div>
<span class="card-tag ${tagClass}">${opening.tag}</span>
`;
card.onclick = () => {
selectedOpening = opening;
renderModal(); // re-render to update selection
};
grid.appendChild(card);
});
catDiv.appendChild(grid);
body.appendChild(catDiv);
});
}
function loadSelectedOpening() {
if (!selectedOpening) {
alert('Please select an opening first.');
return;
}
const pgn = selectedOpening.lines.join('\n');
document.getElementById('pgnInput').value = pgn;
closeModal();
loadLines();
}
// Close modal on backdrop click
document.getElementById('openingsModal').addEventListener('click', function(e) {
if (e.target === this) closeModal();
});
// ============================================================
// CHESS BOARD ENGINE (unchanged from original)
// ============================================================
const PIECES = {
'p': 'https://upload.wikimedia.org/wikipedia/commons/c/c7/Chess_pdt45.svg',
'r': 'https://upload.wikimedia.org/wikipedia/commons/f/ff/Chess_rdt45.svg',
'n': 'https://upload.wikimedia.org/wikipedia/commons/e/ef/Chess_ndt45.svg',
'b': 'https://upload.wikimedia.org/wikipedia/commons/9/98/Chess_bdt45.svg',
'q': 'https://upload.wikimedia.org/wikipedia/commons/4/47/Chess_qdt45.svg',
'k': 'https://upload.wikimedia.org/wikipedia/commons/f/f0/Chess_kdt45.svg',
'P': 'https://upload.wikimedia.org/wikipedia/commons/4/45/Chess_plt45.svg',
'R': 'https://upload.wikimedia.org/wikipedia/commons/7/72/Chess_rlt45.svg',
'N': 'https://upload.wikimedia.org/wikipedia/commons/7/70/Chess_nlt45.svg',
'B': 'https://upload.wikimedia.org/wikipedia/commons/b/b1/Chess_blt45.svg',
'Q': 'https://upload.wikimedia.org/wikipedia/commons/1/15/Chess_qlt45.svg',
'K': 'https://upload.wikimedia.org/wikipedia/commons/4/42/Chess_klt45.svg'
};
let game = new Chess();
let boardElement = document.getElementById('board');
let selectedSquare = null;
let repertoire = [];
let currentLineIndex = -1;
let targetMoves = [];
let currentMovePointer = 0;
let isFlipped = false;
let userSide = 'w';
let isProcessing = false;
function initBoard() {
boardElement.innerHTML = '';
for (let i = 0; i < 64; i++) {
const square = document.createElement('div');
const row = Math.floor(i / 8);
const col = i % 8;
const isLight = (row + col) % 2 === 0;
square.classList.add('square', isLight ? 'light' : 'dark');
square.dataset.index = i;
square.dataset.coord = String.fromCharCode(97 + col) + (8 - row);
square.addEventListener('click', handleSquareClick);
boardElement.appendChild(square);
}
updateBoardUI();
}
function setUserSide(side) {
userSide = side;
const wBtn = document.getElementById('sideWhite');
const bBtn = document.getElementById('sideBlack');
if (side === 'w') {
wBtn.className = "px-6 py-2 rounded-md text-sm font-semibold transition-all bg-blue-600 text-white";
bBtn.className = "px-6 py-2 rounded-md text-sm font-semibold transition-all text-slate-400 hover:text-white";
if (isFlipped) toggleFlip();
} else {
bBtn.className = "px-6 py-2 rounded-md text-sm font-semibold transition-all bg-blue-600 text-white";
wBtn.className = "px-6 py-2 rounded-md text-sm font-semibold transition-all text-slate-400 hover:text-white";
if (!isFlipped) toggleFlip();
}
if (currentLineIndex !== -1) resetCurrentLine();
}
function toggleFlip() {
isFlipped = !isFlipped;
if (isFlipped) boardElement.classList.add('flipped');
else boardElement.classList.remove('flipped');
}
function updateBoardUI() {
const position = game.board();
const squares = boardElement.children;
const history = game.history({ verbose: true });
const lastMove = history.length > 0 ? history[history.length - 1] : null;
for (let i = 0; i < 64; i++) {
const row = Math.floor(i / 8);
const col = i % 8;
const squareData = position[row][col];
const squareEl = squares[i];
squareEl.innerHTML = '';
squareEl.classList.remove('selected', 'valid-target', 'last-move');
if (squareData) {
const img = document.createElement('img');
img.src = PIECES[squareData.color === 'w' ? squareData.type.toUpperCase() : squareData.type];
img.classList.add('piece');
squareEl.appendChild(img);
}
if (lastMove && (squareEl.dataset.coord === lastMove.from || squareEl.dataset.coord === lastMove.to)) {
squareEl.classList.add('last-move');
}
}
}
function handleSquareClick(e) {
if (currentLineIndex === -1 || isProcessing) return;
if (game.turn() !== userSide) return;
const square = e.currentTarget;
const coord = square.dataset.coord;
if (selectedSquare === coord) {
selectedSquare = null;
updateBoardUI();
return;
}
if (selectedSquare) {
const move = game.move({ from: selectedSquare, to: coord, promotion: 'q' });
if (move) { validateMove(move); selectedSquare = null; return; }
else { selectedSquare = null; updateBoardUI(); return; }
}
const piece = game.get(coord);
if (piece && piece.color === userSide) {
selectedSquare = coord;
updateBoardUI();
square.classList.add('selected');
const moves = game.moves({ square: coord, verbose: true });
moves.forEach(m => {
const target = Array.from(boardElement.children).find(s => s.dataset.coord === m.to);
if (target) target.classList.add('valid-target');
});
}
}
function validateMove(move) {
const expectedMove = targetMoves[currentMovePointer];
if (expectedMove && move.san === expectedMove.san) {
showFeedback(true);
currentMovePointer++;
updateProgressUI();
updateBoardUI();
if (currentMovePointer < targetMoves.length) {
isProcessing = true;
setTimeout(makeComputerMove, 600);
} else {
onLineComplete();
}
} else {
showFeedback(false);
game.undo();
updateBoardUI();
}
}
function makeComputerMove() {
if (currentMovePointer >= targetMoves.length) { isProcessing = false; return; }
const nextMove = targetMoves[currentMovePointer];
game.move(nextMove.san);
currentMovePointer++;
updateBoardUI();
updateProgressUI();
isProcessing = false;
if (currentMovePointer >= targetMoves.length) onLineComplete();
}
function onLineComplete() {
document.getElementById('statusLabel').innerText = "Line Complete";
document.getElementById('statusLabel').classList.add('text-green-400');
}
function showFeedback(correct) {
const el = document.getElementById(correct ? 'feedbackSuccess' : 'feedbackError');
el.style.opacity = '1';
const icon = el.querySelector('.feedback-icon');
icon.style.animation = 'none';
icon.offsetHeight;
icon.style.animation = null;
setTimeout(() => { el.style.opacity = '0'; }, 600);
}
function loadLines() {
const input = document.getElementById('pgnInput').value;
let blocks;
if (input.includes('[Event')) {
blocks = input.split(/(?=\[Event\s)/).map(b => b.trim()).filter(b => b.length > 3);
} else {
blocks = input.split(/\n\s*\n/).map(b => b.trim()).filter(b => b.length > 5);
if (blocks.length <= 1) {
blocks = input.split('\n').map(b => b.trim()).filter(b => b.length > 5);
}
}
repertoire = [];
blocks.forEach(block => {
const nameMatch = block.match(/\[Event\s+"([^"]+)"\]/);
const name = nameMatch ? nameMatch[1] : null;
const movesOnly = block.replace(/\[.*?\]\s*/g, '').trim();
const moveLine = movesOnly.split('\n')[0] || movesOnly;
if (movesOnly.length < 3) return;
const tempGame = new Chess();
if (tempGame.load_pgn(movesOnly)) {
repertoire.push({ pgn: block, moves: tempGame.history({ verbose: true }), name, preview: moveLine.trim() });
}
});
if (repertoire.length > 0) {
renderLineList();
document.getElementById('lineListContainer').classList.remove('hidden');
selectLine(0);
}
}
function renderLineList() {
const list = document.getElementById('lineList');
list.innerHTML = '';
repertoire.forEach((line, i) => {
const btn = document.createElement('button');
btn.className = "text-left p-3 rounded bg-slate-700 hover:bg-slate-600 transition-colors text-sm border-l-4 border-transparent";
if (i === currentLineIndex) btn.classList.add('border-blue-500', 'bg-slate-600');
const label = line.name || `Line ${i+1}`;
const preview = line.preview.substring(0, 48).replace(/\s+/g, ' ') + "...";
btn.innerHTML = `<div class="font-bold">${label}</div><div class="text-slate-400 truncate text-xs">${preview}</div>`;
btn.onclick = () => selectLine(i);
list.appendChild(btn);
});
}
function selectLine(index) {
currentLineIndex = index;
targetMoves = repertoire[index].moves;
resetCurrentLine();
renderLineList();
}
function resetCurrentLine() {
game.reset();
currentMovePointer = 0;
isProcessing = false;
updateProgressUI();
updateBoardUI();
document.getElementById('statusLabel').innerText = "Active Training";
document.getElementById('statusLabel').classList.remove('text-green-400');
if (userSide === 'b') { isProcessing = true; setTimeout(makeComputerMove, 600); }
}
function updateProgressUI() {
const historyContainer = document.getElementById('moveHistory');
historyContainer.innerHTML = '';
targetMoves.forEach((m, i) => {
const span = document.createElement('span');
const moveNum = Math.floor(i / 2) + 1;
const isWhite = i % 2 === 0;
span.className = `px-2 py-1 rounded text-xs transition-colors ${i < currentMovePointer ? 'bg-blue-900/50 text-blue-300 border border-blue-800' : 'bg-slate-700/50 text-slate-500 border border-slate-700'}`;
span.innerText = `${isWhite ? moveNum + '.' : ''} ${m.san}`;
historyContainer.appendChild(span);
});
document.getElementById('moveCounter').innerText = `${currentMovePointer} / ${targetMoves.length}`;
}
initBoard();
window.onload = () => {
const lines = [
'[Event "Caro-Kann - Classical (Bf5)"]\n1. e4 c6 2. d4 d5 3. Nc3 dxe4 4. Nxe4 Bf5 5. Ng3 Bg6 6. h4 h6 7. Nf3 Nd7 8. h5 Bh7 9. Bd3 Bxd3 10. Qxd3 *',
'[Event "Caro-Kann - Advance Variation"]\n1. e4 c6 2. d4 d5 3. e5 Bf5 4. Nf3 e6 5. Be2 c5 6. Be3 cxd4 7. Nxd4 Bg6 8. O-O Nd7 *',
'[Event "Caro-Kann - Exchange Variation"]\n1. e4 c6 2. d4 d5 3. exd5 cxd5 4. Bd3 Nc6 5. c3 Nf6 6. Bf4 Bg4 7. Qb3 Qd7 8. Nd2 e6 *',
'[Event "Caro-Kann - Panov-Botvinnik Attack"]\n1. e4 c6 2. d4 d5 3. exd5 cxd5 4. c4 Nf6 5. Nc3 e6 6. Nf3 Be7 7. cxd5 Nxd5 8. Bc4 O-O *',
'[Event "Pirc - Classical System"]\n1. e4 d6 2. d4 Nf6 3. Nc3 g6 4. Nf3 Bg7 5. Be2 O-O 6. O-O c5 7. d5 Nbd7',
'[Event "Pirc - Austrian Attack"]\n1. e4 d6 2. d4 Nf6 3. Nc3 g6 4. f4 Bg7 5. Nf3 O-O 6. Bd3 Nc6 7. e5 dxe5 8. fxe5 Nd7',
'[Event "Pirc - 150 Attack"]\n1. e4 d6 2. d4 Nf6 3. Nc3 g6 4. Be3 Bg7 5. Qd2 c6 6. f3 b5 7. Nge2 Nbd7',
'[Event "Jobava1-simple"]\n1. d4 d5 2. Nc3 Nf6 3. Bf4 Nc6 4. Nb5 e5 5. Bxe5 Nxe5 6. dxe5 Ne4 $6 7. Qxd5 $3 Qxd5 $6 8. Nxc7+ Kd8 9. Nxd5 Be6 10. Rd1 *',
'[Event "Jobava2-simple"]\n1. d4 Nf6 2. Nc3 d5 3. Bf4 e6 4. e3 c5 5. Nb5 Na6 6. c3 Bd7 7. a4 Bxb5 8. Bxb5+ Nd7 9. Nf3 Nc7 $2 10. Bxc7 Qxc7 11. Ne5 *',
'[Event "Jobava3-moreXPoppon"]\n1. d4 d5 2. Nc3 Nf6 3. Bf4 a6 4. e3 e6 5. Nf3 c5 6. dxc5 Bxc5 7. Bd3 Nc6 8. O-O O-O 9. e4 *',
'[Event "Jobava3-continued-queenBlunder"]\n1. d4 Nf6 2. Nc3 d5 3. Bf4 a6 4. e3 e6 5. Nf3 c5 6. dxc5 Bxc5 7. Bd3 Nc6 8. O-O O-O 9. e4 d4 10. e5 dxc3 11. exf6 Qxf6 $4 12. Bg5 *',
'[Event "Jobava-Declined1-ForcePircNiceSacri"]\n1. d4 Nf6 2. Nc3 g6 3. e4 d6 4. Be3 Bg7 5. Qd2 O-O 6. O-O-O c6 7. Bh6 a5 8. h4 a4 9. h5 Nxh5 $2 10. Rxh5 $3 gxh5 $4 11. Qg5 a3 12. Qxg7',
'[Event "Jobava-Declined2-QueenTrap"]\n1. d4 d5 2. Nc3 e6 3. e4 dxe4 4. Nxe4 Nf6 5. Nxf6+ Qxf6 6. Nf3 Bd6 7. Bd3 O-O $4 8. Bg5 *',
'[Event "KID - Classical Main Line"]\n1. d4 Nf6 2. c4 g6 3. Nc3 Bg7 4. e4 d6 5. Nf3 O-O 6. Be2 e5 7. O-O Nc6 8. d5 Ne7',
'[Event "KID - vs London System"]\n1. d4 Nf6 2. Nf3 g6 3. Bf4 Bg7 4. e3 O-O 5. Be2 d6 6. O-O Nbd7',
'[Event "Modern Defense - Main Line"]\n1. e4 g6 2. d4 Bg7 3. Nc3 d6 4. Nf3 Nf6 5. Be2 O-O 6. O-O',
'[Event "Budapest 1"]\n1. d4 Nf6 2. c4 e5 3. d5 Bc5 4. Bg5 Ne4 5. Bxd8 Bxf2# 0-1',
'[Event "Budapest 2"]\n1. d4 Nf6 2. c4 e5 3. dxe5 Ng4 4. Nf3 d6 5. exd6 Bxd6 6. h3 Nxf2 7. Kxf2 Bg3+ 8.Kxg3 Qxd1 *',
'[Event "French1"]\n1. e4 e6 2. d4 d5 3. e5 c5 4. c3 Nc6 5. Bb5 Bd7 6. Nf3 Nxe5 7. Bxd7+ Nxd7 *',
'[Event "French2"]\n1. e4 e6 2. d4 d5 3. e5 c5 4. c3 Nc6 5. Nf3 Bd7 6. Bd3 cxd4 7. cxd4 Qb6 8. O-O Nxd4 9. Nxd4 Qxd4 *',
'[Event "French3"]\n1. e4 e6 2. Nc3 d5 3. Nf3 d4 4. Nb5 c5 5. a4 a6 6. Na3 Bd6 *',
'[Event "French4"]\n1. e4 e6 2. d4 d5 3. Nf3 dxe4 4. Ne5 *',
'[Event "French5"]\n1. e4 e6 2. c3 d5 3. d3 Nc6 4. Nf3 dxe4 5. dxe4 Qxd1+ 6. Kxd1 Nf6 *',
'[Event "French6"]\n1. e4 e6 2. Nf3 d5 3. exd5 exd5 4. Nc3 d4 5. Nb5 c5 6. Qe2+ Be6 7. Qe5 Nc6 8. Nc7+ Kd7 9. Nxe6 Nxe5 10. Nxd8 Nxf3+ 11. gxf3 Rxd8 *',
'[Event "French7"]\n1. g3 e6 2. Bg2 d5 3. d4 c5 4. e3 Nf6 5. Ne2 Be7 6. O-O O-O 7. dxc5 Qa5 8. c4 dxc4 9. Qd4 Nc6 10. Qxc4 e5 11. Bd2 Qxc5 12. Qxc5 Bxc5 *'
];
document.getElementById('pgnInput').value = lines.join('\n');
loadLines();
};
</script>
</body>
</html>