Raven7 commited on
Commit
073c4dc
Β·
verified Β·
1 Parent(s): 52b4b86

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +326 -18
index.html CHANGED
@@ -1,19 +1,327 @@
1
- <!doctype html>
2
  <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
  <html>
3
+ <head>
4
+ <style>
5
+ .board {
6
+ width: 480px;
7
+ height: 480px;
8
+ border: 2px solid #333;
9
+ display: grid;
10
+ grid-template-columns: repeat(8, 1fr);
11
+ }
12
+
13
+ .square {
14
+ width: 60px;
15
+ height: 60px;
16
+ display: flex;
17
+ justify-content: center;
18
+ align-items: center;
19
+ font-size: 40px;
20
+ cursor: pointer;
21
+ position: relative;
22
+ }
23
+
24
+ .white {
25
+ background: #fff;
26
+ }
27
+
28
+ .black {
29
+ background: #999;
30
+ }
31
+
32
+ .highlight {
33
+ background: rgba(255, 255, 0, 0.5);
34
+ }
35
+
36
+ .possible-move::after {
37
+ content: '';
38
+ position: absolute;
39
+ width: 20px;
40
+ height: 20px;
41
+ background: rgba(0, 255, 0, 0.3);
42
+ border-radius: 50%;
43
+ }
44
+
45
+ .captured {
46
+ margin: 20px;
47
+ padding: 10px;
48
+ border: 1px solid #ccc;
49
+ }
50
+
51
+ .captured-piece {
52
+ font-size: 24px;
53
+ margin: 0 5px;
54
+ }
55
+ </style>
56
+ </head>
57
+ <body>
58
+ <div class="board" id="board"></div>
59
+ <div class="captured">
60
+ <div>
61
+ White captured: <span id="whiteCaptured"></span>
62
+ </div>
63
+ <div>
64
+ Black captured: <span id="blackCaptured"></span>
65
+ </div>
66
+ </div>
67
+
68
+ <script>
69
+ const board = document.getElementById('board');
70
+ const whiteCaptured = document.getElementById('whiteCaptured');
71
+ const blackCaptured = document.getElementById('blackCaptured');
72
+ let selectedPiece = null;
73
+ let currentTurn = 'white';
74
+ let whiteCapturedPieces = [];
75
+ let blackCapturedPieces = [];
76
+
77
+ const initialBoard = [
78
+ ['β™œ', 'β™ž', '♝', 'β™›', 'β™š', '♝', 'β™ž', 'β™œ'],
79
+ ['β™Ÿ', 'β™Ÿ', 'β™Ÿ', 'β™Ÿ', 'β™Ÿ', 'β™Ÿ', 'β™Ÿ', 'β™Ÿ'],
80
+ ['', '', '', '', '', '', '', ''],
81
+ ['', '', '', '', '', '', '', ''],
82
+ ['', '', '', '', '', '', '', ''],
83
+ ['', '', '', '', '', '', '', ''],
84
+ ['β™™', 'β™™', 'β™™', 'β™™', 'β™™', 'β™™', 'β™™', 'β™™'],
85
+ ['β™–', 'β™˜', 'β™—', 'β™•', 'β™”', 'β™—', 'β™˜', 'β™–']
86
+ ];
87
+
88
+ let gameBoard = JSON.parse(JSON.stringify(initialBoard));
89
+
90
+ function createBoard() {
91
+ board.innerHTML = '';
92
+ for (let i = 0; i < 8; i++) {
93
+ for (let j = 0; j < 8; j++) {
94
+ const square = document.createElement('div');
95
+ square.className = `square ${(i + j) % 2 === 0 ? 'white' : 'black'}`;
96
+ square.dataset.row = i;
97
+ square.dataset.col = j;
98
+ square.textContent = gameBoard[i][j];
99
+ square.addEventListener('click', handleClick);
100
+ board.appendChild(square);
101
+ }
102
+ }
103
+ }
104
+
105
+ function isWhitePiece(piece) {
106
+ return 'β™”β™•β™–β™—β™˜β™™'.includes(piece);
107
+ }
108
+
109
+ function isBlackPiece(piece) {
110
+ return 'β™šβ™›β™œβ™β™žβ™Ÿ'.includes(piece);
111
+ }
112
+
113
+ function clearHighlights() {
114
+ document.querySelectorAll('.square').forEach(square => {
115
+ square.classList.remove('highlight', 'possible-move');
116
+ });
117
+ }
118
+
119
+ function getPossibleMoves(row, col) {
120
+ const piece = gameBoard[row][col];
121
+ const moves = [];
122
+
123
+ switch (piece) {
124
+ case 'β™”':
125
+ case 'β™š':
126
+ // King moves
127
+ for (let i = -1; i <= 1; i++) {
128
+ for (let j = -1; j <= 1; j++) {
129
+ if (i === 0 && j === 0) continue;
130
+ const newRow = row + i;
131
+ const newCol = col + j;
132
+ if (isValidMove(newRow, newCol, piece)) {
133
+ moves.push([newRow, newCol]);
134
+ }
135
+ }
136
+ }
137
+ break;
138
+
139
+ case 'β™•':
140
+ case 'β™›':
141
+ // Queen moves (combination of rook and bishop)
142
+ moves.push(...getRookMoves(row, col));
143
+ moves.push(...getBishopMoves(row, col));
144
+ break;
145
+
146
+ case 'β™–':
147
+ case 'β™œ':
148
+ // Rook moves
149
+ moves.push(...getRookMoves(row, col));
150
+ break;
151
+
152
+ case 'β™—':
153
+ case '♝':
154
+ // Bishop moves
155
+ moves.push(...getBishopMoves(row, col));
156
+ break;
157
+
158
+ case 'β™˜':
159
+ case 'β™ž':
160
+ // Knight moves
161
+ const knightMoves = [
162
+ [-2, -1], [-2, 1], [-1, -2], [-1, 2],
163
+ [1, -2], [1, 2], [2, -1], [2, 1]
164
+ ];
165
+ for (const [dRow, dCol] of knightMoves) {
166
+ const newRow = row + dRow;
167
+ const newCol = col + dCol;
168
+ if (isValidMove(newRow, newCol, piece)) {
169
+ moves.push([newRow, newCol]);
170
+ }
171
+ }
172
+ break;
173
+
174
+ case 'β™™':
175
+ // White pawn moves
176
+ if (row > 0 && !gameBoard[row - 1][col]) {
177
+ moves.push([row - 1, col]);
178
+ if (row === 6 && !gameBoard[row - 2][col]) {
179
+ moves.push([row - 2, col]);
180
+ }
181
+ }
182
+ // Capture diagonally
183
+ if (row > 0 && col > 0 && isBlackPiece(gameBoard[row - 1][col - 1])) {
184
+ moves.push([row - 1, col - 1]);
185
+ }
186
+ if (row > 0 && col < 7 && isBlackPiece(gameBoard[row - 1][col + 1])) {
187
+ moves.push([row - 1, col + 1]);
188
+ }
189
+ break;
190
+
191
+ case 'β™Ÿ':
192
+ // Black pawn moves
193
+ if (row < 7 && !gameBoard[row + 1][col]) {
194
+ moves.push([row + 1, col]);
195
+ if (row === 1 && !gameBoard[row + 2][col]) {
196
+ moves.push([row + 2, col]);
197
+ }
198
+ }
199
+ // Capture diagonally
200
+ if (row < 7 && col > 0 && isWhitePiece(gameBoard[row + 1][col - 1])) {
201
+ moves.push([row + 1, col - 1]);
202
+ }
203
+ if (row < 7 && col < 7 && isWhitePiece(gameBoard[row + 1][col + 1])) {
204
+ moves.push([row + 1, col + 1]);
205
+ }
206
+ break;
207
+ }
208
+
209
+ return moves;
210
+ }
211
+
212
+ function getRookMoves(row, col) {
213
+ const moves = [];
214
+ const directions = [[0, 1], [0, -1], [1, 0], [-1, 0]];
215
+ for (const [dRow, dCol] of directions) {
216
+ let newRow = row + dRow;
217
+ let newCol = col + dCol;
218
+ while (isValidMove(newRow, newCol, gameBoard[row][col])) {
219
+ moves.push([newRow, newCol]);
220
+ if (gameBoard[newRow][newCol]) break;
221
+ newRow += dRow;
222
+ newCol += dCol;
223
+ }
224
+ }
225
+ return moves;
226
+ }
227
+
228
+ function getBishopMoves(row, col) {
229
+ const moves = [];
230
+ const directions = [[1, 1], [1, -1], [-1, 1], [-1, -1]];
231
+ for (const [dRow, dCol] of directions) {
232
+ let newRow = row + dRow;
233
+ let newCol = col + dCol;
234
+ while (isValidMove(newRow, newCol, gameBoard[row][col])) {
235
+ moves.push([newRow, newCol]);
236
+ if (gameBoard[newRow][newCol]) break;
237
+ newRow += dRow;
238
+ newCol += dCol;
239
+ }
240
+ }
241
+ return moves;
242
+ }
243
+
244
+ function isValidMove(row, col, piece) {
245
+ if (row < 0 || row > 7 || col < 0 || col > 7) return false;
246
+ const targetPiece = gameBoard[row][col];
247
+ if (!targetPiece) return true;
248
+ return isWhitePiece(piece) ? isBlackPiece(targetPiece) : isWhitePiece(targetPiece);
249
+ }
250
+
251
+ function handleClick(event) {
252
+ const row = parseInt(event.target.dataset.row);
253
+ const col = parseInt(event.target.dataset.col);
254
+ const piece = gameBoard[row][col];
255
+
256
+ if (selectedPiece) {
257
+ const selectedRow = parseInt(selectedPiece.dataset.row);
258
+ const selectedCol = parseInt(selectedPiece.dataset.col);
259
+ const possibleMoves = getPossibleMoves(selectedRow, selectedCol);
260
+
261
+ const isValidMove = possibleMoves.some(([r, c]) => r === row && c === col);
262
+
263
+ if (isValidMove) {
264
+ const capturedPiece = gameBoard[row][col];
265
+ if (capturedPiece) {
266
+ if (isWhitePiece(gameBoard[selectedRow][selectedCol])) {
267
+ whiteCapturedPieces.push(capturedPiece);
268
+ } else {
269
+ blackCapturedPieces.push(capturedPiece);
270
+ }
271
+ updateCapturedPieces();
272
+
273
+ if (capturedPiece === 'β™š' || capturedPiece === 'β™”') {
274
+ alert('Game Over! ' + (isWhitePiece(gameBoard[selectedRow][selectedCol]) ? 'White' : 'Black') + ' wins!');
275
+ resetGame();
276
+ return;
277
+ }
278
+ }
279
+
280
+ gameBoard[row][col] = gameBoard[selectedRow][selectedCol];
281
+ gameBoard[selectedRow][selectedCol] = '';
282
+ currentTurn = currentTurn === 'white' ? 'black' : 'white';
283
+ }
284
+
285
+ selectedPiece = null;
286
+ clearHighlights();
287
+ createBoard();
288
+ return;
289
+ }
290
+
291
+ if (!piece) return;
292
+
293
+ const isWhiteTurn = currentTurn === 'white';
294
+ if ((isWhiteTurn && !isWhitePiece(piece)) || (!isWhiteTurn && !isBlackPiece(piece))) {
295
+ return;
296
+ }
297
+
298
+ selectedPiece = event.target;
299
+ clearHighlights();
300
+ event.target.classList.add('highlight');
301
+
302
+ const possibleMoves = getPossibleMoves(row, col);
303
+ possibleMoves.forEach(([r, c]) => {
304
+ const square = document.querySelector(`[data-row="${r}"][data-col="${c}"]`);
305
+ square.classList.add('possible-move');
306
+ });
307
+ }
308
+
309
+ function updateCapturedPieces() {
310
+ whiteCaptured.textContent = whiteCapturedPieces.join(' ');
311
+ blackCaptured.textContent = blackCapturedPieces.join(' ');
312
+ }
313
+
314
+ function resetGame() {
315
+ gameBoard = JSON.parse(JSON.stringify(initialBoard));
316
+ currentTurn = 'white';
317
+ whiteCapturedPieces = [];
318
+ blackCapturedPieces = [];
319
+ selectedPiece = null;
320
+ updateCapturedPieces();
321
+ createBoard();
322
+ }
323
+
324
+ createBoard();
325
+ </script>
326
+ </body>
327
+ </html>