-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathguessboard.htm
More file actions
181 lines (150 loc) · 3.71 KB
/
guessboard.htm
File metadata and controls
181 lines (150 loc) · 3.71 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Chess Square Color Trainer</title>
<style>
body {
font-family: system-ui, sans-serif;
background: #111;
color: #eee;
display: flex;
justify-content: center;
align-items: center;
margin: 0;
}
html, body {
height: 100%;
}
.game {
text-align: center;
padding: 2rem;
border-radius: 12px;
background: #1c1c1c;
box-shadow: 0 10px 30px rgba(0,0,0,0.5);
position: relative;
}
.square {
font-size: 4rem;
margin: 1rem 0;
letter-spacing: 0.1em;
}
button {
font-size: 1.1rem;
padding: 0.6rem 1.2rem;
margin: 0.4rem;
border: none;
border-radius: 8px;
cursor: pointer;
}
.white { background: #eee; color: #111; }
.black { background: #333; color: #eee; }
.peek {
background: #555;
color: #eee;
}
.result {
margin-top: 1rem;
min-height: 1.5em;
}
.score {
margin-top: 0.5rem;
opacity: 0.8;
}
/* Board */
.board {
position: absolute;
top: 50%;
left: 110%;
transform: translateY(-50%);
display: none;
grid-template-columns: repeat(8, 32px);
grid-template-rows: repeat(8, 32px);
border: 2px solid #666;
}
.cell {
width: 32px;
height: 32px;
}
.light { background: #eee; }
.dark { background: #444; }
.peek-wrapper:hover .board {
display: grid;
}
</style>
</head>
<body>
<div class="game">
<h2>Square color?</h2>
<div class="square" id="square">e4</div>
<div>
<button class="white" onclick="guess('white')">White</button>
<button class="black" onclick="guess('black')">Black</button>
</div>
<div class="peek-wrapper" style="margin-top: 0.8rem;">
<button class="peek">Cheat</button>
<div class="board">
<!-- Board generated by JS -->
</div>
</div>
<div class="result" id="result"></div>
<div class="score" id="score">0 / 0</div>
</div>
<script>
const files = ['a','b','c','d','e','f','g','h'];
let currentSquare = '';
let correctColor = '';
let correct = 0;
let total = 0;
function squareColor(square) {
const file = files.indexOf(square[0]);
const rank = parseInt(square[1], 10) - 1;
return ((file + rank) % 2 === 0) ? 'black' : 'white';
}
function newRound() {
const file = files[Math.floor(Math.random() * 8)];
const rank = Math.floor(Math.random() * 8) + 1;
currentSquare = file + rank;
correctColor = squareColor(currentSquare);
document.getElementById('square').textContent = currentSquare;
document.getElementById('result').textContent = '';
}
function guess(color) {
const isCorrect = (color === correctColor);
// Human-readable console log
console.log(
`Square: ${currentSquare} | ` +
`Your guess: ${color} | ` +
`Correct answer: ${correctColor} | ` +
`Result: ${isCorrect ? 'correct' : 'wrong'}`
);
total++;
if (isCorrect) {
correct++;
document.getElementById('result').textContent = '✅ Correct';
} else {
document.getElementById('result').textContent =
`❌ Wrong — ${correctColor}`;
}
document.getElementById('score').textContent =
`${correct} / ${total}`;
setTimeout(newRound, 800);
}
function buildBoard() {
const board = document.querySelector('.board');
board.innerHTML = '';
// Rank 8 → 1 so orientation is correct
for (let rank = 7; rank >= 0; rank--) {
for (let file = 0; file < 8; file++) {
const cell = document.createElement('div');
const isDark = (file + rank) % 2 === 0;
cell.className = `cell ${isDark ? 'dark' : 'light'}`;
board.appendChild(cell);
}
}
}
buildBoard();
newRound();
</script>
</body>
</html>