Spaces:
Running
Running
now add live playing and adding more context of adding a live game of chess with deepseek and other player
Browse files- index.html +254 -34
index.html
CHANGED
|
@@ -85,17 +85,17 @@
|
|
| 85 |
ChessVision Pro ♟️
|
| 86 |
</h1>
|
| 87 |
</div>
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
</div>
|
| 100 |
</header>
|
| 101 |
|
|
@@ -103,12 +103,37 @@
|
|
| 103 |
<div class="grid lg:grid-cols-3 gap-8 items-start">
|
| 104 |
<!-- Left Sidebar -->
|
| 105 |
<div class="space-y-6">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
<div class="bg-gray-800/50 backdrop-blur-sm rounded-xl p-6 border border-gray-700">
|
| 107 |
<h2 class="text-xl font-bold mb-4 flex items-center space-x-2">
|
| 108 |
<i data-feather="users"></i>
|
| 109 |
<span>Game Info</span>
|
| 110 |
</h2>
|
| 111 |
<div class="space-y-3">
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
<div class="flex justify-between">
|
| 113 |
<span class="text-gray-400">Player:</span>
|
| 114 |
<span class="font-semibold text-white">White</span>
|
|
@@ -121,10 +146,13 @@
|
|
| 121 |
<span class="text-gray-400">Turn:</span>
|
| 122 |
<span class="font-semibold text-green-400">White to Move</span>
|
| 123 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
</div>
|
| 125 |
</div>
|
| 126 |
-
|
| 127 |
-
<div class="bg-gray-800/50 backdrop-blur-sm rounded-xl p-6 border border-gray-700">
|
| 128 |
<h2 class="text-xl font-bold mb-4 flex items-center space-x-2">
|
| 129 |
<i data-feather="activity"></i>
|
| 130 |
<span>Statistics</span>
|
|
@@ -163,27 +191,64 @@
|
|
| 163 |
</button>
|
| 164 |
</div>
|
| 165 |
</div>
|
| 166 |
-
|
| 167 |
<!-- Right Sidebar -->
|
| 168 |
<div class="space-y-6">
|
| 169 |
<div class="bg-gray-800/50 backdrop-blur-sm rounded-xl p-6 border border-gray-700">
|
| 170 |
<h2 class="text-xl font-bold mb-4 flex items-center space-x-2">
|
| 171 |
<i data-feather="message-circle"></i>
|
| 172 |
-
<span>Game Context</span>
|
| 173 |
</h2>
|
| 174 |
<div class="space-y-3 text-gray-300">
|
| 175 |
-
|
| 176 |
-
<
|
| 177 |
-
|
| 178 |
-
<li>Full set of chess pieces with proper positioning</li>
|
| 179 |
-
<li>Piece movement animations</li>
|
| 180 |
-
<li>Game state tracking</li>
|
| 181 |
-
<li>Move validation system</li>
|
| 182 |
-
</ul>
|
| 183 |
</div>
|
| 184 |
</div>
|
| 185 |
|
| 186 |
-
<div class="bg-gray-800/50 backdrop-blur-sm rounded-xl p-6 border border-gray-700">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
<h2 class="text-xl font-bold mb-4 flex items-center space-x-2">
|
| 188 |
<i data-feather="clock"></i>
|
| 189 |
<span>Move History</span>
|
|
@@ -237,11 +302,12 @@
|
|
| 237 |
['white-pawn', 'white-pawn', 'white-pawn', 'white-pawn', 'white-pawn', 'white-pawn', 'white-pawn', 'white-pawn'],
|
| 238 |
['white-rook', 'white-knight', 'white-bishop', 'white-queen', 'white-king', 'white-bishop', 'white-knight', 'white-rook']
|
| 239 |
];
|
| 240 |
-
|
| 241 |
let selectedSquare = null;
|
| 242 |
let currentTurn = 'white';
|
| 243 |
-
|
| 244 |
-
|
|
|
|
|
|
|
| 245 |
function createChessBoard() {
|
| 246 |
const board = document.getElementById('chessBoard');
|
| 247 |
board.innerHTML = '';
|
|
@@ -270,7 +336,6 @@
|
|
| 270 |
}
|
| 271 |
}
|
| 272 |
}
|
| 273 |
-
|
| 274 |
// Handle square clicks
|
| 275 |
function handleSquareClick(event) {
|
| 276 |
const square = event.currentTarget;
|
|
@@ -278,6 +343,10 @@
|
|
| 278 |
const col = parseInt(square.dataset.col);
|
| 279 |
const piece = square.querySelector('.piece');
|
| 280 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
// If no piece selected and clicked on own piece
|
| 282 |
if (!selectedSquare && piece && piece.dataset.color === currentTurn) {
|
| 283 |
selectSquare(square);
|
|
@@ -301,10 +370,14 @@
|
|
| 301 |
|
| 302 |
// Attempt to move piece
|
| 303 |
movePiece(selectedSquare, square);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
}
|
| 305 |
}
|
| 306 |
-
|
| 307 |
-
// Select square
|
| 308 |
function selectSquare(square) {
|
| 309 |
deselectSquare(); // Clear any previous selection
|
| 310 |
selectedSquare = square;
|
|
@@ -370,7 +443,6 @@
|
|
| 370 |
square.classList.remove('possible-move');
|
| 371 |
});
|
| 372 |
}
|
| 373 |
-
|
| 374 |
// Move piece
|
| 375 |
function movePiece(fromSquare, toSquare) {
|
| 376 |
const piece = fromSquare.querySelector('.piece');
|
|
@@ -387,12 +459,152 @@
|
|
| 387 |
currentTurn = currentTurn === 'white' ? 'black' : 'white';
|
| 388 |
updateTurnDisplay();
|
| 389 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
deselectSquare();
|
| 391 |
}, 150);
|
| 392 |
}
|
| 393 |
}
|
| 394 |
|
| 395 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 396 |
function updateTurnDisplay() {
|
| 397 |
const turnElements = document.querySelectorAll('[class*="turn"]');
|
| 398 |
turnElements.forEach(el => {
|
|
@@ -401,12 +613,20 @@
|
|
| 401 |
el.classList.add(currentTurn === 'white' ? 'text-green-400' : 'text-blue-400');
|
| 402 |
});
|
| 403 |
}
|
| 404 |
-
|
| 405 |
// Initialize the board
|
| 406 |
document.addEventListener('DOMContentLoaded', () => {
|
| 407 |
createChessBoard();
|
|
|
|
| 408 |
feather.replace();
|
| 409 |
});
|
| 410 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
</body>
|
| 412 |
</html>
|
|
|
|
| 85 |
ChessVision Pro ♟️
|
| 86 |
</h1>
|
| 87 |
</div>
|
| 88 |
+
<div class="flex items-center space-x-4">
|
| 89 |
+
<button class="bg-green-600 hover:bg-green-700 px-4 py-2 rounded-lg transition-colors flex items-center space-x-2">
|
| 90 |
+
<i data-feather="refresh-cw"></i>
|
| 91 |
+
<span>New Game</span>
|
| 92 |
+
</button>
|
| 93 |
+
<button class="bg-blue-600 hover:bg-blue-700 px-4 py-2 rounded-lg transition-colors flex items-center space-x-2">
|
| 94 |
+
<i data-feather="users"></i>
|
| 95 |
+
<span>Multiplayer</span>
|
| 96 |
+
</button>
|
| 97 |
+
</div>
|
| 98 |
+
</div>
|
| 99 |
</div>
|
| 100 |
</header>
|
| 101 |
|
|
|
|
| 103 |
<div class="grid lg:grid-cols-3 gap-8 items-start">
|
| 104 |
<!-- Left Sidebar -->
|
| 105 |
<div class="space-y-6">
|
| 106 |
+
<div class="bg-gray-800/50 backdrop-blur-sm rounded-xl p-6 border border-gray-700">
|
| 107 |
+
<h2 class="text-xl font-bold mb-4 flex items-center space-x-2">
|
| 108 |
+
<i data-feather="users"></i>
|
| 109 |
+
<span>Game Mode</span>
|
| 110 |
+
</h2>
|
| 111 |
+
<div class="space-y-3">
|
| 112 |
+
<button class="w-full bg-purple-600 hover:bg-purple-700 px-4 py-3 rounded-lg transition-colors flex items-center space-x-2 justify-center game-mode-btn" data-mode="ai">
|
| 113 |
+
<i data-feather="cpu"></i>
|
| 114 |
+
<span>Play vs AI (DeepSeek)</span>
|
| 115 |
+
</button>
|
| 116 |
+
<button class="w-full bg-indigo-600 hover:bg-indigo-700 px-4 py-3 rounded-lg transition-colors flex items-center space-x-2 justify-center game-mode-btn" data-mode="multiplayer">
|
| 117 |
+
<i data-feather="users"></i>
|
| 118 |
+
<span>Live Multiplayer</span>
|
| 119 |
+
</button>
|
| 120 |
+
<button class="w-full bg-gray-600 hover:bg-gray-700 px-4 py-3 rounded-lg transition-colors flex items-center space-x-2 justify-center game-mode-btn" data-mode="local">
|
| 121 |
+
<i data-feather="user"></i>
|
| 122 |
+
<span>Local Play</span>
|
| 123 |
+
</button>
|
| 124 |
+
</div>
|
| 125 |
+
</div>
|
| 126 |
+
|
| 127 |
<div class="bg-gray-800/50 backdrop-blur-sm rounded-xl p-6 border border-gray-700">
|
| 128 |
<h2 class="text-xl font-bold mb-4 flex items-center space-x-2">
|
| 129 |
<i data-feather="users"></i>
|
| 130 |
<span>Game Info</span>
|
| 131 |
</h2>
|
| 132 |
<div class="space-y-3">
|
| 133 |
+
<div class="flex justify-between">
|
| 134 |
+
<span class="text-gray-400">Mode:</span>
|
| 135 |
+
<span class="font-semibold text-white" id="currentMode">Local Play</span>
|
| 136 |
+
</div>
|
| 137 |
<div class="flex justify-between">
|
| 138 |
<span class="text-gray-400">Player:</span>
|
| 139 |
<span class="font-semibold text-white">White</span>
|
|
|
|
| 146 |
<span class="text-gray-400">Turn:</span>
|
| 147 |
<span class="font-semibold text-green-400">White to Move</span>
|
| 148 |
</div>
|
| 149 |
+
<div class="flex justify-between" id="aiStatus" style="display: none;">
|
| 150 |
+
<span class="text-gray-400">AI Status:</span>
|
| 151 |
+
<span class="font-semibold text-yellow-400">Ready</span>
|
| 152 |
+
</div>
|
| 153 |
</div>
|
| 154 |
</div>
|
| 155 |
+
<div class="bg-gray-800/50 backdrop-blur-sm rounded-xl p-6 border border-gray-700">
|
|
|
|
| 156 |
<h2 class="text-xl font-bold mb-4 flex items-center space-x-2">
|
| 157 |
<i data-feather="activity"></i>
|
| 158 |
<span>Statistics</span>
|
|
|
|
| 191 |
</button>
|
| 192 |
</div>
|
| 193 |
</div>
|
|
|
|
| 194 |
<!-- Right Sidebar -->
|
| 195 |
<div class="space-y-6">
|
| 196 |
<div class="bg-gray-800/50 backdrop-blur-sm rounded-xl p-6 border border-gray-700">
|
| 197 |
<h2 class="text-xl font-bold mb-4 flex items-center space-x-2">
|
| 198 |
<i data-feather="message-circle"></i>
|
| 199 |
+
<span>Live Game Context</span>
|
| 200 |
</h2>
|
| 201 |
<div class="space-y-3 text-gray-300">
|
| 202 |
+
<div id="gameContext">
|
| 203 |
+
<p><strong>🎯 Current Mode: Local Play</strong></p>
|
| 204 |
+
<p class="text-sm">Play against yourself or with a friend on the same device.</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
</div>
|
| 206 |
</div>
|
| 207 |
|
| 208 |
+
<div class="bg-gray-800/50 backdrop-blur-sm rounded-xl p-6 border border-gray-700" id="aiPanel" style="display: none;">
|
| 209 |
+
<h2 class="text-xl font-bold mb-4 flex items-center space-x-2">
|
| 210 |
+
<i data-feather="cpu"></i>
|
| 211 |
+
<span>DeepSeek AI</span>
|
| 212 |
+
</h2>
|
| 213 |
+
<div class="space-y-3">
|
| 214 |
+
<div class="flex justify-between">
|
| 215 |
+
<span class="text-gray-400">AI Level:</span>
|
| 216 |
+
<select class="bg-gray-700 text-white rounded px-2 py-1" id="aiLevel">
|
| 217 |
+
<option value="beginner">Beginner</option>
|
| 218 |
+
<option value="intermediate" selected>Intermediate</option>
|
| 219 |
+
<option value="advanced">Advanced</option>
|
| 220 |
+
<option value="expert">Expert</option>
|
| 221 |
+
</select>
|
| 222 |
+
</div>
|
| 223 |
+
<div class="flex justify-between">
|
| 224 |
+
<span class="text-gray-400">Thinking:</span>
|
| 225 |
+
<span class="font-semibold text-yellow-400" id="aiThinking">No</span>
|
| 226 |
+
</div>
|
| 227 |
+
</div>
|
| 228 |
+
</div>
|
| 229 |
+
|
| 230 |
+
<div class="bg-gray-800/50 backdrop-blur-sm rounded-xl p-6 border border-gray-700" id="multiplayerPanel" style="display: none;">
|
| 231 |
+
<h2 class="text-xl font-bold mb-4 flex items-center space-x-2">
|
| 232 |
+
<i data-feather="globe"></i>
|
| 233 |
+
<span>Live Multiplayer</span>
|
| 234 |
+
</h2>
|
| 235 |
+
<div class="space-y-3">
|
| 236 |
+
<button class="w-full bg-green-600 hover:bg-green-700 px-4 py-3 rounded-lg transition-colors flex items-center space-x-2 justify-center" id="createGameBtn">
|
| 237 |
+
<i data-feather="plus"></i>
|
| 238 |
+
<span>Create Game Room</span>
|
| 239 |
+
</button>
|
| 240 |
+
<div class="flex space-x-2">
|
| 241 |
+
<input type="text" placeholder="Room ID" class="flex-1 bg-gray-700 text-white rounded px-3 py-2" id="roomIdInput">
|
| 242 |
+
<button class="bg-blue-600 hover:bg-blue-700 px-4 py-2 rounded transition-colors">
|
| 243 |
+
<i data-feather="log-in"></i>
|
| 244 |
+
</button>
|
| 245 |
+
</div>
|
| 246 |
+
<div class="text-center text-sm text-gray-400" id="roomStatus">
|
| 247 |
+
No active room
|
| 248 |
+
</div>
|
| 249 |
+
</div>
|
| 250 |
+
</div>
|
| 251 |
+
<div class="bg-gray-800/50 backdrop-blur-sm rounded-xl p-6 border border-gray-700">
|
| 252 |
<h2 class="text-xl font-bold mb-4 flex items-center space-x-2">
|
| 253 |
<i data-feather="clock"></i>
|
| 254 |
<span>Move History</span>
|
|
|
|
| 302 |
['white-pawn', 'white-pawn', 'white-pawn', 'white-pawn', 'white-pawn', 'white-pawn', 'white-pawn', 'white-pawn'],
|
| 303 |
['white-rook', 'white-knight', 'white-bishop', 'white-queen', 'white-king', 'white-bishop', 'white-knight', 'white-rook']
|
| 304 |
];
|
|
|
|
| 305 |
let selectedSquare = null;
|
| 306 |
let currentTurn = 'white';
|
| 307 |
+
let gameMode = 'local';
|
| 308 |
+
let gameRoom = null;
|
| 309 |
+
let isPlayerWhite = true;
|
| 310 |
+
// Create chess board
|
| 311 |
function createChessBoard() {
|
| 312 |
const board = document.getElementById('chessBoard');
|
| 313 |
board.innerHTML = '';
|
|
|
|
| 336 |
}
|
| 337 |
}
|
| 338 |
}
|
|
|
|
| 339 |
// Handle square clicks
|
| 340 |
function handleSquareClick(event) {
|
| 341 |
const square = event.currentTarget;
|
|
|
|
| 343 |
const col = parseInt(square.dataset.col);
|
| 344 |
const piece = square.querySelector('.piece');
|
| 345 |
|
| 346 |
+
// Check if it's player's turn based on game mode
|
| 347 |
+
if (gameMode === 'ai' && currentTurn === 'black') return;
|
| 348 |
+
if (gameMode === 'multiplayer' && ((isPlayerWhite && currentTurn === 'black') || (!isPlayerWhite && currentTurn === 'white'))) return;
|
| 349 |
+
|
| 350 |
// If no piece selected and clicked on own piece
|
| 351 |
if (!selectedSquare && piece && piece.dataset.color === currentTurn) {
|
| 352 |
selectSquare(square);
|
|
|
|
| 370 |
|
| 371 |
// Attempt to move piece
|
| 372 |
movePiece(selectedSquare, square);
|
| 373 |
+
|
| 374 |
+
// If playing against AI and it's AI's turn
|
| 375 |
+
if (gameMode === 'ai' && currentTurn === 'black') {
|
| 376 |
+
setTimeout(makeAIMove, 1000);
|
| 377 |
+
}
|
| 378 |
}
|
| 379 |
}
|
| 380 |
+
// Select square
|
|
|
|
| 381 |
function selectSquare(square) {
|
| 382 |
deselectSquare(); // Clear any previous selection
|
| 383 |
selectedSquare = square;
|
|
|
|
| 443 |
square.classList.remove('possible-move');
|
| 444 |
});
|
| 445 |
}
|
|
|
|
| 446 |
// Move piece
|
| 447 |
function movePiece(fromSquare, toSquare) {
|
| 448 |
const piece = fromSquare.querySelector('.piece');
|
|
|
|
| 459 |
currentTurn = currentTurn === 'white' ? 'black' : 'white';
|
| 460 |
updateTurnDisplay();
|
| 461 |
|
| 462 |
+
// If multiplayer, send move to server
|
| 463 |
+
if (gameMode === 'multiplayer' && gameRoom) {
|
| 464 |
+
sendMoveToServer(fromSquare, toSquare);
|
| 465 |
+
}
|
| 466 |
+
|
| 467 |
deselectSquare();
|
| 468 |
}, 150);
|
| 469 |
}
|
| 470 |
}
|
| 471 |
|
| 472 |
+
// Make AI move (simulated)
|
| 473 |
+
function makeAIMove() {
|
| 474 |
+
if (gameMode !== 'ai' || currentTurn !== 'black') return;
|
| 475 |
+
|
| 476 |
+
// Show AI thinking status
|
| 477 |
+
document.getElementById('aiThinking').textContent = 'Yes';
|
| 478 |
+
|
| 479 |
+
setTimeout(() => {
|
| 480 |
+
// Find all possible moves for black pieces
|
| 481 |
+
const blackPieces = document.querySelectorAll('.piece[data-color="black"]');
|
| 482 |
+
const possibleMoves = [];
|
| 483 |
+
|
| 484 |
+
blackPieces.forEach(piece => {
|
| 485 |
+
const square = piece.parentElement;
|
| 486 |
+
const row = parseInt(square.dataset.row);
|
| 487 |
+
const col = parseInt(square.dataset.col);
|
| 488 |
+
|
| 489 |
+
// Simple AI logic - move random piece to random valid position
|
| 490 |
+
const pieceType = piece.dataset.type;
|
| 491 |
+
let moves = [];
|
| 492 |
+
|
| 493 |
+
if (pieceType === 'pawn') {
|
| 494 |
+
moves.push({ row: row + 1, col: col });
|
| 495 |
+
moves.push({ row: row + 1, col: col - 1 });
|
| 496 |
+
moves.push({ row: row + 1, col: col + 1 });
|
| 497 |
+
} else if (pieceType === 'knight') {
|
| 498 |
+
moves.push({ row: row - 2, col: col - 1 });
|
| 499 |
+
moves.push({ row: row - 2, col: col + 1 });
|
| 500 |
+
moves.push({ row: row - 1, col: col - 2 });
|
| 501 |
+
moves.push({ row: row - 1, col: col + 2 });
|
| 502 |
+
moves.push({ row: row + 1, col: col - 2 });
|
| 503 |
+
moves.push({ row: row + 1, col: col + 2 });
|
| 504 |
+
moves.push({ row: row + 2, col: col - 1 });
|
| 505 |
+
moves.push({ row: row + 2, col: col + 1 });
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
// Filter valid moves
|
| 509 |
+
moves = moves.filter(move =>
|
| 510 |
+
move.row >= 0 && move.row < 8 && move.col >= 0 && move.col < 8
|
| 511 |
+
);
|
| 512 |
+
|
| 513 |
+
moves.forEach(move => {
|
| 514 |
+
const targetSquare = document.querySelector(`[data-row="${move.row}"][data-col="${move.col}"]');
|
| 515 |
+
if (targetSquare && (!targetSquare.querySelector('.piece') || targetSquare.querySelector('.piece[data-color="white"]'))) {
|
| 516 |
+
possibleMoves.push({ from: square, to: targetSquare });
|
| 517 |
+
}
|
| 518 |
+
});
|
| 519 |
+
});
|
| 520 |
+
|
| 521 |
+
// Make a random move if available
|
| 522 |
+
if (possibleMoves.length > 0) {
|
| 523 |
+
const randomMove = possibleMoves[Math.floor(Math.random() * possibleMoves.length)];
|
| 524 |
+
movePiece(randomMove.from, randomMove.to);
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
document.getElementById('aiThinking').textContent = 'No';
|
| 528 |
+
}, 1500);
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
// Game mode selection
|
| 532 |
+
function setGameMode(mode) {
|
| 533 |
+
gameMode = mode;
|
| 534 |
+
document.getElementById('currentMode').textContent =
|
| 535 |
+
mode === 'ai' ? 'AI (DeepSeek)' :
|
| 536 |
+
mode === 'multiplayer' ? 'Live Multiplayer' : 'Local Play';
|
| 537 |
+
|
| 538 |
+
// Update UI based on mode
|
| 539 |
+
document.getElementById('aiStatus').style.display = mode === 'ai' ? 'flex' : 'none';
|
| 540 |
+
document.getElementById('aiPanel').style.display = mode === 'ai' ? 'block' : 'none';
|
| 541 |
+
document.getElementById('multiplayerPanel').style.display = mode === 'multiplayer' ? 'block' : 'none';
|
| 542 |
+
|
| 543 |
+
// Update game context
|
| 544 |
+
const context = document.getElementById('gameContext');
|
| 545 |
+
if (mode === 'ai') {
|
| 546 |
+
context.innerHTML = `
|
| 547 |
+
<p><strong>🤖 Playing vs AI</strong></p>
|
| 548 |
+
<p class="text-sm">Challenge DeepSeek AI with adjustable difficulty levels.</p>
|
| 549 |
+
<ul class="list-disc list-inside space-y-1 ml-2 text-sm">
|
| 550 |
+
<li>Smart move prediction</li>
|
| 551 |
+
<li>Multiple difficulty levels</li>
|
| 552 |
+
<li>Real-time analysis</li>
|
| 553 |
+
</ul>
|
| 554 |
+
`;
|
| 555 |
+
} else if (mode === 'multiplayer') {
|
| 556 |
+
context.innerHTML = `
|
| 557 |
+
<p><strong>🌐 Live Multiplayer</strong></p>
|
| 558 |
+
<p class="text-sm">Play against real opponents worldwide in real-time.</p>
|
| 559 |
+
<ul class="list-disc list-inside space-y-1 ml-2 text-sm">
|
| 560 |
+
<li>Real-time game synchronization</li>
|
| 561 |
+
<li>Chat with opponents</li>
|
| 562 |
+
<li>Elo rating system</li>
|
| 563 |
+
</ul>
|
| 564 |
+
`;
|
| 565 |
+
} else {
|
| 566 |
+
context.innerHTML = `
|
| 567 |
+
<p><strong>🎯 Current Mode: Local Play</strong></p>
|
| 568 |
+
<p class="text-sm">Play against yourself or with a friend on the same device.</p>
|
| 569 |
+
`;
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
// Reset game state for new mode
|
| 573 |
+
createChessBoard();
|
| 574 |
+
currentTurn = 'white';
|
| 575 |
+
updateTurnDisplay();
|
| 576 |
+
}
|
| 577 |
+
|
| 578 |
+
// Send move to multiplayer server (simulated)
|
| 579 |
+
function sendMoveToServer(fromSquare, toSquare) {
|
| 580 |
+
console.log('Sending move to server:', {
|
| 581 |
+
from: { row: fromSquare.dataset.row, col: fromSquare.dataset.col },
|
| 582 |
+
to: { row: toSquare.dataset.row, col: toSquare.dataset.col }
|
| 583 |
+
});
|
| 584 |
+
|
| 585 |
+
// Simulate server response
|
| 586 |
+
setTimeout(() => {
|
| 587 |
+
document.getElementById('roomStatus').textContent = 'Move sent to opponent';
|
| 588 |
+
}, 500);
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
// Initialize game mode buttons
|
| 592 |
+
function initGameModes() {
|
| 593 |
+
document.querySelectorAll('.game-mode-btn').forEach(btn => {
|
| 594 |
+
btn.addEventListener('click', () => {
|
| 595 |
+
setGameMode(btn.dataset.mode);
|
| 596 |
+
});
|
| 597 |
+
});
|
| 598 |
+
|
| 599 |
+
// Multiplayer buttons
|
| 600 |
+
document.getElementById('createGameBtn').addEventListener('click', () => {
|
| 601 |
+
const roomId = Math.random().toString(36).substring(2, 8).toUpperCase();
|
| 602 |
+
document.getElementById('roomIdInput').value = roomId;
|
| 603 |
+
gameRoom = roomId;
|
| 604 |
+
document.getElementById('roomStatus').textContent = `Room created: ${roomId}`;
|
| 605 |
+
});
|
| 606 |
+
}
|
| 607 |
+
// Update turn display
|
| 608 |
function updateTurnDisplay() {
|
| 609 |
const turnElements = document.querySelectorAll('[class*="turn"]');
|
| 610 |
turnElements.forEach(el => {
|
|
|
|
| 613 |
el.classList.add(currentTurn === 'white' ? 'text-green-400' : 'text-blue-400');
|
| 614 |
});
|
| 615 |
}
|
|
|
|
| 616 |
// Initialize the board
|
| 617 |
document.addEventListener('DOMContentLoaded', () => {
|
| 618 |
createChessBoard();
|
| 619 |
+
initGameModes();
|
| 620 |
feather.replace();
|
| 621 |
});
|
| 622 |
+
|
| 623 |
+
// Add multiplayer functionality
|
| 624 |
+
document.getElementById('createGameBtn').addEventListener('click', function() {
|
| 625 |
+
const roomId = Math.random().toString(36).substring(2, 8).toUpperCase();
|
| 626 |
+
document.getElementById('roomIdInput').value = roomId;
|
| 627 |
+
gameRoom = roomId;
|
| 628 |
+
document.getElementById('roomStatus').textContent = `Room created: ${roomId}`;
|
| 629 |
+
});
|
| 630 |
+
</script>
|
| 631 |
</body>
|
| 632 |
</html>
|