CCsuper commited on
Commit
b06b77c
·
verified ·
1 Parent(s): 32f6b54

no board is shown - Initial Deployment

Browse files
Files changed (3) hide show
  1. README.md +7 -5
  2. index.html +461 -18
  3. prompts.txt +2 -0
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Gomoku
3
- emoji: 🐨
4
- colorFrom: indigo
5
- colorTo: indigo
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: gomoku
3
+ emoji: 🐳
4
+ colorFrom: blue
5
+ colorTo: pink
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,462 @@
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 lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Gomoku (Five in a Row) - Human vs AI</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
9
+ <style>
10
+ .board {
11
+ display: grid;
12
+ grid-template-columns: repeat(15, 1fr);
13
+ grid-template-rows: repeat(15, 1fr);
14
+ gap: 1px;
15
+ background-color: #deb887;
16
+ padding: 10px;
17
+ border-radius: 5px;
18
+ box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
19
+ width: 600px;
20
+ height: 600px;
21
+ }
22
+ .board-container {
23
+ width: 620px;
24
+ height: 620px;
25
+ }
26
+ .cell {
27
+ aspect-ratio: 1/1;
28
+ background-color: rgba(222, 184, 135, 0.8);
29
+ display: flex;
30
+ justify-content: center;
31
+ align-items: center;
32
+ cursor: pointer;
33
+ transition: all 0.2s ease;
34
+ position: relative;
35
+ }
36
+ .cell:hover {
37
+ background-color: rgba(222, 184, 135, 0.6);
38
+ }
39
+ .cell::before {
40
+ content: '';
41
+ position: absolute;
42
+ width: 100%;
43
+ height: 100%;
44
+ border: 1px solid rgba(139, 69, 19, 0.3);
45
+ }
46
+ .piece {
47
+ width: 80%;
48
+ height: 80%;
49
+ border-radius: 50%;
50
+ z-index: 10;
51
+ }
52
+ .black {
53
+ background: radial-gradient(circle at 30% 30%, #666, #000);
54
+ box-shadow: 0 3px 5px rgba(0, 0, 0, 0.5);
55
+ }
56
+ .white {
57
+ background: radial-gradient(circle at 30% 30%, #fff, #ddd);
58
+ box-shadow: 0 3px 5px rgba(0, 0, 0, 0.3);
59
+ }
60
+ .win-line {
61
+ position: absolute;
62
+ background-color: rgba(255, 0, 0, 0.7);
63
+ z-index: 5;
64
+ }
65
+ @media (max-width: 640px) {
66
+ .board {
67
+ grid-template-columns: repeat(15, minmax(0, 1fr));
68
+ grid-template-rows: repeat(15, minmax(0, 1fr));
69
+ gap: 0.5px;
70
+ padding: 5px;
71
+ width: 300px;
72
+ height: 300px;
73
+ }
74
+ .board-container {
75
+ width: 310px;
76
+ height: 310px;
77
+ }
78
+ }
79
+ </style>
80
+ </head>
81
+ <body class="bg-amber-50 min-h-screen flex flex-col items-center justify-center p-4">
82
+ <div class="max-w-4xl w-full">
83
+ <h1 class="text-3xl md:text-4xl font-bold text-center text-amber-900 mb-6">Gomoku (Five in a Row)</h1>
84
+
85
+ <div class="flex flex-col md:flex-row gap-6 items-center md:items-start">
86
+ <div class="board-container relative mx-auto">
87
+ <div id="board" class="board"></div>
88
+ <div id="win-line" class="win-line hidden"></div>
89
+ </div>
90
+
91
+ <div class="bg-white p-6 rounded-lg shadow-md w-full md:w-64">
92
+ <div class="flex justify-between items-center mb-4">
93
+ <h2 class="text-xl font-semibold text-gray-800">Game Info</h2>
94
+ <button id="reset-btn" class="p-2 rounded-full bg-amber-100 text-amber-800 hover:bg-amber-200 transition">
95
+ <i data-feather="refresh-cw"></i>
96
+ </button>
97
+ </div>
98
+
99
+ <div class="mb-6">
100
+ <div class="flex items-center justify-between mb-2">
101
+ <span class="font-medium">Player (Black)</span>
102
+ <div class="piece black w-6 h-6"></div>
103
+ </div>
104
+ <div class="flex items-center justify-between">
105
+ <span class="font-medium">AI (White)</span>
106
+ <div class="piece white w-6 h-6"></div>
107
+ </div>
108
+ </div>
109
+
110
+ <div id="status" class="p-3 bg-amber-100 rounded text-center text-amber-900 font-medium mb-4">
111
+ Your turn (Black)
112
+ </div>
113
+
114
+ <div class="space-y-2">
115
+ <div class="flex items-center gap-2">
116
+ <i data-feather="info" class="text-amber-600"></i>
117
+ <span class="text-sm text-gray-600">First move must be center</span>
118
+ </div>
119
+ <div class="flex items-center gap-2">
120
+ <i data-feather="award" class="text-amber-600"></i>
121
+ <span class="text-sm text-gray-600">Connect 5 to win</span>
122
+ </div>
123
+ </div>
124
+ </div>
125
+ </div>
126
+ </div>
127
+
128
+ <script>
129
+ feather.replace();
130
+
131
+ document.addEventListener('DOMContentLoaded', () => {
132
+ const board = document.getElementById('board');
133
+ const status = document.getElementById('status');
134
+ const resetBtn = document.getElementById('reset-btn');
135
+ const winLine = document.getElementById('win-line');
136
+
137
+ const BOARD_SIZE = 15;
138
+ let currentPlayer = 'black'; // Human starts first
139
+ let gameBoard = Array(BOARD_SIZE).fill().map(() => Array(BOARD_SIZE).fill(null));
140
+ let gameOver = false;
141
+
142
+ // Initialize board
143
+ function initializeBoard() {
144
+ board.innerHTML = '';
145
+ for (let row = 0; row < BOARD_SIZE; row++) {
146
+ for (let col = 0; col < BOARD_SIZE; col++) {
147
+ const cell = document.createElement('div');
148
+ cell.className = 'cell';
149
+ cell.dataset.row = row;
150
+ cell.dataset.col = col;
151
+
152
+ // Center point for first move
153
+ if (row === Math.floor(BOARD_SIZE/2) && col === Math.floor(BOARD_SIZE/2)) {
154
+ cell.classList.add('bg-amber-300');
155
+ }
156
+
157
+ cell.addEventListener('click', () => handleCellClick(row, col));
158
+ board.appendChild(cell);
159
+ }
160
+ }
161
+ }
162
+
163
+ // Handle cell click
164
+ function handleCellClick(row, col) {
165
+ if (gameOver || gameBoard[row][col] !== null) return;
166
+
167
+ // First move must be center
168
+ if (currentPlayer === 'black' &&
169
+ Object.values(gameBoard.flat()).every(val => val === null) &&
170
+ !(row === Math.floor(BOARD_SIZE/2) && col === Math.floor(BOARD_SIZE/2))) {
171
+ status.textContent = 'First move must be center!';
172
+ return;
173
+ }
174
+
175
+ placePiece(row, col, currentPlayer);
176
+
177
+ if (checkWin(row, col, currentPlayer)) {
178
+ gameOver = true;
179
+ status.textContent = currentPlayer === 'black' ? 'You win!' : 'AI wins!';
180
+ return;
181
+ }
182
+
183
+ if (isBoardFull()) {
184
+ gameOver = true;
185
+ status.textContent = "It's a draw!";
186
+ return;
187
+ }
188
+
189
+ currentPlayer = currentPlayer === 'black' ? 'white' : 'black';
190
+ status.textContent = currentPlayer === 'black' ? 'Your turn (Black)' : 'AI thinking...';
191
+
192
+ if (currentPlayer === 'white') {
193
+ setTimeout(makeAIMove, 800);
194
+ }
195
+ }
196
+
197
+ // Place a piece on the board
198
+ function placePiece(row, col, color) {
199
+ gameBoard[row][col] = color;
200
+ const cell = document.querySelector(`.cell[data-row="${row}"][data-col="${col}"]`);
201
+ const piece = document.createElement('div');
202
+ piece.className = `piece ${color}`;
203
+ cell.appendChild(piece);
204
+ }
205
+
206
+ // Check for win condition
207
+ function checkWin(row, col, color) {
208
+ const directions = [
209
+ [0, 1], // horizontal
210
+ [1, 0], // vertical
211
+ [1, 1], // diagonal down-right
212
+ [1, -1] // diagonal down-left
213
+ ];
214
+
215
+ for (const [dx, dy] of directions) {
216
+ let count = 1;
217
+
218
+ // Check in positive direction
219
+ for (let i = 1; i <= 4; i++) {
220
+ const newRow = row + i * dx;
221
+ const newCol = col + i * dy;
222
+
223
+ if (newRow < 0 || newRow >= BOARD_SIZE || newCol < 0 || newCol >= BOARD_SIZE ||
224
+ gameBoard[newRow][newCol] !== color) {
225
+ break;
226
+ }
227
+ count++;
228
+ }
229
+
230
+ // Check in negative direction
231
+ for (let i = 1; i <= 4; i++) {
232
+ const newRow = row - i * dx;
233
+ const newCol = col - i * dy;
234
+
235
+ if (newRow < 0 || newRow >= BOARD_SIZE || newCol < 0 || newCol >= BOARD_SIZE ||
236
+ gameBoard[newRow][newCol] !== color) {
237
+ break;
238
+ }
239
+ count++;
240
+ }
241
+
242
+ if (count >= 5) {
243
+ drawWinLine(row, col, dx, dy);
244
+ return true;
245
+ }
246
+ }
247
+
248
+ return false;
249
+ }
250
+
251
+ // Draw win line
252
+ function drawWinLine(row, col, dx, dy) {
253
+ // Find start and end of the winning line
254
+ let startRow = row, startCol = col;
255
+ let endRow = row, endCol = col;
256
+
257
+ while (startRow - dx >= 0 && startCol - dy >= 0 &&
258
+ startCol - dy < BOARD_SIZE &&
259
+ gameBoard[startRow - dx][startCol - dy] === gameBoard[row][col]) {
260
+ startRow -= dx;
261
+ startCol -= dy;
262
+ }
263
+
264
+ while (endRow + dx < BOARD_SIZE && endCol + dy < BOARD_SIZE &&
265
+ endCol + dy >= 0 &&
266
+ gameBoard[endRow + dx][endCol + dy] === gameBoard[row][col]) {
267
+ endRow += dx;
268
+ endCol += dy;
269
+ }
270
+
271
+ // Get cell positions
272
+ const startCell = document.querySelector(`.cell[data-row="${startRow}"][data-col="${startCol}"]`);
273
+ const endCell = document.querySelector(`.cell[data-row="${endRow}"][data-col="${endCol}"]`);
274
+
275
+ const startRect = startCell.getBoundingClientRect();
276
+ const endRect = endCell.getBoundingClientRect();
277
+ const boardRect = board.getBoundingClientRect();
278
+
279
+ // Calculate line position and dimensions
280
+ const lineWidth = Math.sqrt(
281
+ Math.pow(endRect.left - startRect.left, 2) +
282
+ Math.pow(endRect.top - startRect.top, 2)
283
+ ) + startRect.width;
284
+
285
+ const lineAngle = Math.atan2(
286
+ endRect.top + endRect.height/2 - (startRect.top + startRect.height/2),
287
+ endRect.left + endRect.width/2 - (startRect.left + startRect.width/2)
288
+ );
289
+
290
+ // Position the line
291
+ winLine.style.width = `${lineWidth}px`;
292
+ winLine.style.height = '4px';
293
+ winLine.style.left = `${startRect.left - boardRect.left + startRect.width/2}px`;
294
+ winLine.style.top = `${startRect.top - boardRect.top + startRect.height/2}px`;
295
+ winLine.style.transformOrigin = '0 0';
296
+ winLine.style.transform = `rotate(${lineAngle}rad)`;
297
+ winLine.classList.remove('hidden');
298
+ }
299
+
300
+ // Check if board is full
301
+ function isBoardFull() {
302
+ return gameBoard.flat().every(cell => cell !== null);
303
+ }
304
+
305
+ // AI move logic
306
+ function makeAIMove() {
307
+ if (gameOver) return;
308
+
309
+ // Simple AI: first try to win, then block player, then random move
310
+ let bestMove = null;
311
+
312
+ // 1. Check if AI can win in the next move
313
+ bestMove = findWinningMove('white');
314
+
315
+ // 2. If not, check if player can win in the next move and block
316
+ if (!bestMove) {
317
+ bestMove = findWinningMove('black');
318
+ }
319
+
320
+ // 3. If no immediate win/loss, make a strategic move
321
+ if (!bestMove) {
322
+ bestMove = findStrategicMove();
323
+ }
324
+
325
+ // 4. If no strategic move found, make a random move
326
+ if (!bestMove) {
327
+ bestMove = findRandomMove();
328
+ }
329
+
330
+ if (bestMove) {
331
+ const [row, col] = bestMove;
332
+ placePiece(row, col, 'white');
333
+
334
+ if (checkWin(row, col, 'white')) {
335
+ gameOver = true;
336
+ status.textContent = 'AI wins!';
337
+ return;
338
+ }
339
+
340
+ if (isBoardFull()) {
341
+ gameOver = true;
342
+ status.textContent = "It's a draw!";
343
+ return;
344
+ }
345
+
346
+ currentPlayer = 'black';
347
+ status.textContent = 'Your turn (Black)';
348
+ }
349
+ }
350
+
351
+ // Find winning move for given player
352
+ function findWinningMove(player) {
353
+ for (let row = 0; row < BOARD_SIZE; row++) {
354
+ for (let col = 0; col < BOARD_SIZE; col++) {
355
+ if (gameBoard[row][col] === null) {
356
+ gameBoard[row][col] = player;
357
+ if (checkWin(row, col, player)) {
358
+ gameBoard[row][col] = null; // Undo move
359
+ return [row, col];
360
+ }
361
+ gameBoard[row][col] = null; // Undo move
362
+ }
363
+ }
364
+ }
365
+ return null;
366
+ }
367
+
368
+ // Find strategic move (prioritize center and existing patterns)
369
+ function findStrategicMove() {
370
+ const center = Math.floor(BOARD_SIZE/2);
371
+ const directions = [[0,1],[1,0],[1,1],[1,-1]];
372
+ let bestScore = -1;
373
+ let bestMove = null;
374
+
375
+ for (let row = 0; row < BOARD_SIZE; row++) {
376
+ for (let col = 0; col < BOARD_SIZE; col++) {
377
+ if (gameBoard[row][col] !== null) continue;
378
+
379
+ // Prefer center positions
380
+ let score = (BOARD_SIZE - Math.abs(row - center) - Math.abs(col - center)) / 2;
381
+
382
+ // Check for patterns around this cell
383
+ for (const [dx, dy] of directions) {
384
+ // Check for AI patterns to extend
385
+ const aiPattern = countPattern(row, col, dx, dy, 'white');
386
+ if (aiPattern >= 2) score += aiPattern * 5;
387
+
388
+ // Check for player patterns to block
389
+ const playerPattern = countPattern(row, col, dx, dy, 'black');
390
+ if (playerPattern >= 2) score += playerPattern * 3;
391
+ }
392
+
393
+ if (score > bestScore) {
394
+ bestScore = score;
395
+ bestMove = [row, col];
396
+ }
397
+ }
398
+ }
399
+
400
+ return bestMove;
401
+ }
402
+
403
+ // Count consecutive pieces in a direction
404
+ function countPattern(row, col, dx, dy, player) {
405
+ let count = 0;
406
+
407
+ for (let i = -4; i <= 4; i++) {
408
+ if (i === 0) continue; // Skip the current cell
409
+
410
+ const newRow = row + i * dx;
411
+ const newCol = col + i * dy;
412
+
413
+ if (newRow >= 0 && newRow < BOARD_SIZE && newCol >= 0 && newCol < BOARD_SIZE) {
414
+ if (gameBoard[newRow][newCol] === player) {
415
+ count++;
416
+ } else if (gameBoard[newRow][newCol] !== null) {
417
+ count = 0;
418
+ break;
419
+ }
420
+ }
421
+ }
422
+
423
+ return count;
424
+ }
425
+
426
+ // Find random valid move
427
+ function findRandomMove() {
428
+ const emptyCells = [];
429
+
430
+ for (let row = 0; row < BOARD_SIZE; row++) {
431
+ for (let col = 0; col < BOARD_SIZE; col++) {
432
+ if (gameBoard[row][col] === null) {
433
+ emptyCells.push([row, col]);
434
+ }
435
+ }
436
+ }
437
+
438
+ if (emptyCells.length > 0) {
439
+ return emptyCells[Math.floor(Math.random() * emptyCells.length)];
440
+ }
441
+
442
+ return null;
443
+ }
444
+
445
+ // Reset game
446
+ function resetGame() {
447
+ gameBoard = Array(BOARD_SIZE).fill().map(() => Array(BOARD_SIZE).fill(null));
448
+ currentPlayer = 'black';
449
+ gameOver = false;
450
+ status.textContent = 'Your turn (Black)';
451
+ winLine.classList.add('hidden');
452
+ initializeBoard();
453
+ }
454
+
455
+ resetBtn.addEventListener('click', resetGame);
456
+
457
+ // Initialize the game
458
+ initializeBoard();
459
+ });
460
+ </script>
461
+ </body>
462
  </html>
prompts.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ write a game of 五子棋人机对战
2
+ no board is shown