Use icon as paws
Browse files- README.md +9 -5
- index.html +572 -18
README.md
CHANGED
|
@@ -1,10 +1,14 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: undefined
|
| 3 |
+
colorFrom: green
|
| 4 |
+
colorTo: green
|
| 5 |
+
emoji: 🐳
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite-v3
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Welcome to your new DeepSite project!
|
| 13 |
+
This project was created with [DeepSite](https://deepsite.hf.co).
|
| 14 |
+
|
index.html
CHANGED
|
@@ -1,19 +1,573 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-scale=1.0">
|
| 6 |
+
<title>ChessMaster Pro</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<script src="https://unpkg.com/feather-icons"></script>
|
| 9 |
+
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
| 10 |
+
<style>
|
| 11 |
+
.chess-square {
|
| 12 |
+
position: relative;
|
| 13 |
+
width: 100%;
|
| 14 |
+
padding-bottom: 100%;
|
| 15 |
+
}
|
| 16 |
+
.chess-piece {
|
| 17 |
+
position: absolute;
|
| 18 |
+
width: 80%;
|
| 19 |
+
height: 80%;
|
| 20 |
+
top: 10%;
|
| 21 |
+
left: 10%;
|
| 22 |
+
background-size: contain;
|
| 23 |
+
background-repeat: no-repeat;
|
| 24 |
+
background-position: center;
|
| 25 |
+
cursor: pointer;
|
| 26 |
+
transition: transform 0.2s ease;
|
| 27 |
+
z-index: 10;
|
| 28 |
+
}
|
| 29 |
+
.chess-piece.dragging {
|
| 30 |
+
z-index: 20;
|
| 31 |
+
transform: scale(1.1);
|
| 32 |
+
}
|
| 33 |
+
.legal-move {
|
| 34 |
+
position: absolute;
|
| 35 |
+
width: 30%;
|
| 36 |
+
height: 30%;
|
| 37 |
+
border-radius: 50%;
|
| 38 |
+
background-color: rgba(0, 255, 0, 0.3);
|
| 39 |
+
top: 35%;
|
| 40 |
+
left: 35%;
|
| 41 |
+
z-index: 5;
|
| 42 |
+
}
|
| 43 |
+
.selected {
|
| 44 |
+
background-color: rgba(255, 215, 0, 0.3) !important;
|
| 45 |
+
}
|
| 46 |
+
.check {
|
| 47 |
+
background-color: rgba(255, 0, 0, 0.3) !important;
|
| 48 |
+
}
|
| 49 |
+
.captured-piece {
|
| 50 |
+
width: 30px;
|
| 51 |
+
height: 30px;
|
| 52 |
+
background-size: contain;
|
| 53 |
+
background-repeat: no-repeat;
|
| 54 |
+
background-position: center;
|
| 55 |
+
margin: 2px;
|
| 56 |
+
}
|
| 57 |
+
@media (max-width: 768px) {
|
| 58 |
+
.captured-piece {
|
| 59 |
+
width: 20px;
|
| 60 |
+
height: 20px;
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
.promotion-modal {
|
| 64 |
+
display: none;
|
| 65 |
+
position: fixed;
|
| 66 |
+
top: 0;
|
| 67 |
+
left: 0;
|
| 68 |
+
width: 100%;
|
| 69 |
+
height: 100%;
|
| 70 |
+
background-color: rgba(0, 0, 0, 0.7);
|
| 71 |
+
z-index: 100;
|
| 72 |
+
justify-content: center;
|
| 73 |
+
align-items: center;
|
| 74 |
+
}
|
| 75 |
+
.promotion-options {
|
| 76 |
+
display: flex;
|
| 77 |
+
background-color: #2d3748;
|
| 78 |
+
padding: 20px;
|
| 79 |
+
border-radius: 10px;
|
| 80 |
+
}
|
| 81 |
+
.promotion-piece {
|
| 82 |
+
width: 60px;
|
| 83 |
+
height: 60px;
|
| 84 |
+
margin: 10px;
|
| 85 |
+
background-size: contain;
|
| 86 |
+
background-repeat: no-repeat;
|
| 87 |
+
background-position: center;
|
| 88 |
+
cursor: pointer;
|
| 89 |
+
transition: transform 0.2s;
|
| 90 |
+
}
|
| 91 |
+
.promotion-piece:hover {
|
| 92 |
+
transform: scale(1.1);
|
| 93 |
+
}
|
| 94 |
+
</style>
|
| 95 |
+
</head>
|
| 96 |
+
<body class="bg-gray-900 text-white min-h-screen flex flex-col">
|
| 97 |
+
<header class="bg-indigo-900 py-4 px-6 shadow-lg">
|
| 98 |
+
<div class="container mx-auto flex justify-between items-center">
|
| 99 |
+
<h1 class="text-2xl md:text-3xl font-bold flex items-center">
|
| 100 |
+
<i data-feather="shield" class="mr-2"></i> ChessMaster Pro
|
| 101 |
+
</h1>
|
| 102 |
+
<div class="flex space-x-4">
|
| 103 |
+
<button id="resetBtn" class="bg-red-600 hover:bg-red-700 px-4 py-2 rounded-lg flex items-center">
|
| 104 |
+
<i data-feather="refresh-cw" class="mr-2"></i> Reset
|
| 105 |
+
</button>
|
| 106 |
+
<button id="undoBtn" class="bg-blue-600 hover:bg-blue-700 px-4 py-2 rounded-lg flex items-center">
|
| 107 |
+
<i data-feather="corner-up-left" class="mr-2"></i> Undo
|
| 108 |
+
</button>
|
| 109 |
+
</div>
|
| 110 |
+
</div>
|
| 111 |
+
</header>
|
| 112 |
+
|
| 113 |
+
<main class="flex-grow container mx-auto px-4 py-8 flex flex-col md:flex-row items-center md:items-start justify-center gap-8">
|
| 114 |
+
<!-- Game info section -->
|
| 115 |
+
<div class="w-full md:w-1/4 bg-gray-800 p-6 rounded-lg shadow-lg">
|
| 116 |
+
<div class="mb-6">
|
| 117 |
+
<h2 class="text-xl font-semibold mb-2">Game Status</h2>
|
| 118 |
+
<div id="gameStatus" class="bg-gray-700 p-3 rounded">White's turn</div>
|
| 119 |
+
</div>
|
| 120 |
+
|
| 121 |
+
<div class="mb-6">
|
| 122 |
+
<h2 class="text-xl font-semibold mb-2">Captured Pieces</h2>
|
| 123 |
+
<div class="bg-gray-700 p-3 rounded">
|
| 124 |
+
<h3 class="font-medium mb-1">White captured:</h3>
|
| 125 |
+
<div id="whiteCaptured" class="flex flex-wrap"></div>
|
| 126 |
+
|
| 127 |
+
<h3 class="font-medium mt-3 mb-1">Black captured:</h3>
|
| 128 |
+
<div id="blackCaptured" class="flex flex-wrap"></div>
|
| 129 |
+
</div>
|
| 130 |
+
</div>
|
| 131 |
+
|
| 132 |
+
<div>
|
| 133 |
+
<h2 class="text-xl font-semibold mb-2">Move History</h2>
|
| 134 |
+
<div id="moveHistory" class="bg-gray-700 p-3 rounded max-h-40 overflow-y-auto">
|
| 135 |
+
<!-- Move history will be populated here -->
|
| 136 |
+
</div>
|
| 137 |
+
</div>
|
| 138 |
+
</div>
|
| 139 |
+
|
| 140 |
+
<!-- Chess board -->
|
| 141 |
+
<div class="w-full md:w-2/4 max-w-lg mx-auto">
|
| 142 |
+
<div class="bg-gray-800 p-4 rounded-lg shadow-lg">
|
| 143 |
+
<div id="chessBoard" class="grid grid-cols-8 aspect-square">
|
| 144 |
+
<!-- Board will be generated by JavaScript -->
|
| 145 |
+
</div>
|
| 146 |
+
</div>
|
| 147 |
+
</div>
|
| 148 |
+
|
| 149 |
+
<!-- Controls and info -->
|
| 150 |
+
<div class="w-full md:w-1/4 bg-gray-800 p-6 rounded-lg shadow-lg">
|
| 151 |
+
<div class="mb-6">
|
| 152 |
+
<h2 class="text-xl font-semibold mb-2">Current Player</h2>
|
| 153 |
+
<div id="currentPlayer" class="bg-gray-700 p-3 rounded flex items-center">
|
| 154 |
+
<div class="w-6 h-6 bg-white rounded-full mr-2"></div> White
|
| 155 |
+
</div>
|
| 156 |
+
</div>
|
| 157 |
+
|
| 158 |
+
<div class="mb-6">
|
| 159 |
+
<h2 class="text-xl font-semibold mb-2">Game Controls</h2>
|
| 160 |
+
<div class="space-y-2">
|
| 161 |
+
<button id="flipBoardBtn" class="w-full bg-purple-600 hover:bg-purple-700 py-2 rounded flex items-center justify-center">
|
| 162 |
+
<i data-feather="rotate-cw" class="mr-2"></i> Flip Board
|
| 163 |
+
</button>
|
| 164 |
+
<button id="hintBtn" class="w-full bg-green-600 hover:bg-green-700 py-2 rounded flex items-center justify-center">
|
| 165 |
+
<i data-feather="help-circle" class="mr-2"></i> Show Hints
|
| 166 |
+
</button>
|
| 167 |
+
</div>
|
| 168 |
+
</div>
|
| 169 |
+
|
| 170 |
+
<div>
|
| 171 |
+
<h2 class="text-xl font-semibold mb-2">Game Time</h2>
|
| 172 |
+
<div class="bg-gray-700 p-3 rounded">
|
| 173 |
+
<div class="flex justify-between">
|
| 174 |
+
<span>White:</span>
|
| 175 |
+
<span id="whiteTime">10:00</span>
|
| 176 |
+
</div>
|
| 177 |
+
<div class="flex justify-between mt-2">
|
| 178 |
+
<span>Black:</span>
|
| 179 |
+
<span id="blackTime">10:00</span>
|
| 180 |
+
</div>
|
| 181 |
+
</div>
|
| 182 |
+
</div>
|
| 183 |
+
</div>
|
| 184 |
+
</main>
|
| 185 |
+
|
| 186 |
+
<!-- Promotion modal -->
|
| 187 |
+
<div id="promotionModal" class="promotion-modal">
|
| 188 |
+
<div class="promotion-options">
|
| 189 |
+
<div class="promotion-piece" data-piece="q"></div>
|
| 190 |
+
<div class="promotion-piece" data-piece="r"></div>
|
| 191 |
+
<div class="promotion-piece" data-piece="b"></div>
|
| 192 |
+
<div class="promotion-piece" data-piece="n"></div>
|
| 193 |
+
</div>
|
| 194 |
+
</div>
|
| 195 |
+
|
| 196 |
+
<footer class="bg-indigo-900 py-4 text-center">
|
| 197 |
+
<p>ChessMaster Pro ♟️ - Play like a grandmaster!</p>
|
| 198 |
+
</footer>
|
| 199 |
+
|
| 200 |
+
<script>
|
| 201 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 202 |
+
feather.replace();
|
| 203 |
+
|
| 204 |
+
// Chess game implementation
|
| 205 |
+
const chessBoard = document.getElementById('chessBoard');
|
| 206 |
+
const gameStatus = document.getElementById('gameStatus');
|
| 207 |
+
const currentPlayer = document.getElementById('currentPlayer');
|
| 208 |
+
const whiteCaptured = document.getElementById('whiteCaptured');
|
| 209 |
+
const blackCaptured = document.getElementById('blackCaptured');
|
| 210 |
+
const moveHistory = document.getElementById('moveHistory');
|
| 211 |
+
const resetBtn = document.getElementById('resetBtn');
|
| 212 |
+
const undoBtn = document.getElementById('undoBtn');
|
| 213 |
+
const flipBoardBtn = document.getElementById('flipBoardBtn');
|
| 214 |
+
const hintBtn = document.getElementById('hintBtn');
|
| 215 |
+
const promotionModal = document.getElementById('promotionModal');
|
| 216 |
+
|
| 217 |
+
let board = [];
|
| 218 |
+
let selectedPiece = null;
|
| 219 |
+
let legalMoves = [];
|
| 220 |
+
let isWhiteTurn = true;
|
| 221 |
+
let boardFlipped = false;
|
| 222 |
+
let moveHistoryList = [];
|
| 223 |
+
let capturedPieces = { white: [], black: [] };
|
| 224 |
+
|
| 225 |
+
// Initialize the chess board
|
| 226 |
+
function initializeBoard() {
|
| 227 |
+
board = [
|
| 228 |
+
['br', 'bn', 'bb', 'bq', 'bk', 'bb', 'bn', 'br'],
|
| 229 |
+
['bp', 'bp', 'bp', 'bp', 'bp', 'bp', 'bp', 'bp'],
|
| 230 |
+
['', '', '', '', '', '', '', ''],
|
| 231 |
+
['', '', '', '', '', '', '', ''],
|
| 232 |
+
['', '', '', '', '', '', '', ''],
|
| 233 |
+
['', '', '', '', '', '', '', ''],
|
| 234 |
+
['wp', 'wp', 'wp', 'wp', 'wp', 'wp', 'wp', 'wp'],
|
| 235 |
+
['wr', 'wn', 'wb', 'wq', 'wk', 'wb', 'wn', 'wr']
|
| 236 |
+
];
|
| 237 |
+
|
| 238 |
+
renderBoard();
|
| 239 |
+
updateGameStatus();
|
| 240 |
+
updateCapturedPieces();
|
| 241 |
+
moveHistory.innerHTML = '';
|
| 242 |
+
moveHistoryList = [];
|
| 243 |
+
isWhiteTurn = true;
|
| 244 |
+
updateCurrentPlayerDisplay();
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
// Render the chess board
|
| 248 |
+
function renderBoard() {
|
| 249 |
+
chessBoard.innerHTML = '';
|
| 250 |
+
|
| 251 |
+
for (let row = 0; row < 8; row++) {
|
| 252 |
+
for (let col = 0; col < 8; col++) {
|
| 253 |
+
const displayRow = boardFlipped ? 7 - row : row;
|
| 254 |
+
const displayCol = boardFlipped ? 7 - col : col;
|
| 255 |
+
|
| 256 |
+
const square = document.createElement('div');
|
| 257 |
+
square.className = `chess-square ${(displayRow + displayCol) % 2 === 0 ? 'bg-amber-100' : 'bg-amber-800'}`;
|
| 258 |
+
square.dataset.row = row;
|
| 259 |
+
square.dataset.col = col;
|
| 260 |
+
|
| 261 |
+
const piece = board[row][col];
|
| 262 |
+
if (piece) {
|
| 263 |
+
const pieceElement = document.createElement('div');
|
| 264 |
+
pieceElement.className = `chess-piece ${piece[0] === 'w' ? 'white-piece' : 'black-piece'}`;
|
| 265 |
+
pieceElement.style.backgroundImage = `url('http://static.photos/chess/${piece[0] === 'w' ? 'white' : 'black'}/200x200/${piece[1]})`;
|
| 266 |
+
pieceElement.dataset.piece = piece;
|
| 267 |
+
square.appendChild(pieceElement);
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
square.addEventListener('click', handleSquareClick);
|
| 271 |
+
chessBoard.appendChild(square);
|
| 272 |
+
}
|
| 273 |
+
}
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
// Handle square click
|
| 277 |
+
function handleSquareClick(event) {
|
| 278 |
+
const square = event.target.closest('.chess-square');
|
| 279 |
+
if (!square) return;
|
| 280 |
+
|
| 281 |
+
const row = parseInt(square.dataset.row);
|
| 282 |
+
const col = parseInt(square.dataset.col);
|
| 283 |
+
const piece = board[row][col];
|
| 284 |
+
|
| 285 |
+
// If a piece is already selected
|
| 286 |
+
if (selectedPiece) {
|
| 287 |
+
// Check if the clicked square is a legal move
|
| 288 |
+
const isLegalMove = legalMoves.some(move =>
|
| 289 |
+
move.toRow === row && move.toCol === col
|
| 290 |
+
);
|
| 291 |
+
|
| 292 |
+
if (isLegalMove) {
|
| 293 |
+
movePiece(selectedPiece.row, selectedPiece.col, row, col);
|
| 294 |
+
clearSelection();
|
| 295 |
+
} else if (piece && piece[0] === (isWhiteTurn ? 'w' : 'b')) {
|
| 296 |
+
// Select a different piece of the same color
|
| 297 |
+
selectPiece(row, col);
|
| 298 |
+
} else {
|
| 299 |
+
// Clicked on an empty square or opponent's piece without a legal move
|
| 300 |
+
clearSelection();
|
| 301 |
+
}
|
| 302 |
+
} else if (piece && piece[0] === (isWhiteTurn ? 'w' : 'b')) {
|
| 303 |
+
// Select a piece
|
| 304 |
+
selectPiece(row, col);
|
| 305 |
+
}
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
// Select a piece
|
| 309 |
+
function selectPiece(row, col) {
|
| 310 |
+
clearSelection();
|
| 311 |
+
|
| 312 |
+
selectedPiece = { row, col, piece: board[row][col] };
|
| 313 |
+
highlightSquare(row, col, true);
|
| 314 |
+
|
| 315 |
+
// Calculate legal moves (simplified for this example)
|
| 316 |
+
legalMoves = calculateLegalMoves(row, col);
|
| 317 |
+
highlightLegalMoves(legalMoves);
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
// Clear selection
|
| 321 |
+
function clearSelection() {
|
| 322 |
+
if (selectedPiece) {
|
| 323 |
+
highlightSquare(selectedPiece.row, selectedPiece.col, false);
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
selectedPiece = null;
|
| 327 |
+
legalMoves = [];
|
| 328 |
+
|
| 329 |
+
// Remove all legal move indicators
|
| 330 |
+
document.querySelectorAll('.legal-move').forEach(el => el.remove());
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
// Highlight a square
|
| 334 |
+
function highlightSquare(row, col, isSelected) {
|
| 335 |
+
const displayRow = boardFlipped ? 7 - row : row;
|
| 336 |
+
const displayCol = boardFlipped ? 7 - col : col;
|
| 337 |
+
const index = displayRow * 8 + displayCol;
|
| 338 |
+
const square = chessBoard.children[index];
|
| 339 |
+
|
| 340 |
+
if (isSelected) {
|
| 341 |
+
square.classList.add('selected');
|
| 342 |
+
} else {
|
| 343 |
+
square.classList.remove('selected');
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
// Highlight legal moves
|
| 348 |
+
function highlightLegalMoves(moves) {
|
| 349 |
+
moves.forEach(move => {
|
| 350 |
+
const displayRow = boardFlipped ? 7 - move.toRow : move.toRow;
|
| 351 |
+
const displayCol = boardFlipped ? 7 - move.toCol : move.toCol;
|
| 352 |
+
const index = displayRow * 8 + displayCol;
|
| 353 |
+
const square = chessBoard.children[index];
|
| 354 |
+
|
| 355 |
+
const indicator = document.createElement('div');
|
| 356 |
+
indicator.className = 'legal-move';
|
| 357 |
+
square.appendChild(indicator);
|
| 358 |
+
});
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
// Calculate legal moves (simplified version)
|
| 362 |
+
function calculateLegalMoves(row, col) {
|
| 363 |
+
const piece = board[row][col];
|
| 364 |
+
const moves = [];
|
| 365 |
+
|
| 366 |
+
// This is a simplified version - a real implementation would be more complex
|
| 367 |
+
if (piece[1] === 'p') { // Pawn
|
| 368 |
+
const direction = piece[0] === 'w' ? -1 : 1;
|
| 369 |
+
|
| 370 |
+
// Move forward
|
| 371 |
+
if (isInBounds(row + direction, col) && !board[row + direction][col]) {
|
| 372 |
+
moves.push({ toRow: row + direction, toCol: col });
|
| 373 |
+
|
| 374 |
+
// Initial double move
|
| 375 |
+
if ((piece[0] === 'w' && row === 6) || (piece[0] === 'b' && row === 1)) {
|
| 376 |
+
if (!board[row + 2 * direction][col]) {
|
| 377 |
+
moves.push({ toRow: row + 2 * direction, toCol: col });
|
| 378 |
+
}
|
| 379 |
+
}
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
// Capture diagonally
|
| 383 |
+
for (let offset of [-1, 1]) {
|
| 384 |
+
if (isInBounds(row + direction, col + offset)) {
|
| 385 |
+
const target = board[row + direction][col + offset];
|
| 386 |
+
if (target && target[0] !== piece[0]) {
|
| 387 |
+
moves.push({ toRow: row + direction, toCol: col + offset });
|
| 388 |
+
}
|
| 389 |
+
}
|
| 390 |
+
}
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
// Add more piece movement logic here...
|
| 394 |
+
|
| 395 |
+
return moves;
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
// Check if coordinates are within bounds
|
| 399 |
+
function isInBounds(row, col) {
|
| 400 |
+
return row >= 0 && row < 8 && col >= 0 && col < 8;
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
// Move a piece
|
| 404 |
+
function movePiece(fromRow, fromCol, toRow, toCol) {
|
| 405 |
+
const piece = board[fromRow][fromCol];
|
| 406 |
+
const targetPiece = board[toRow][toCol];
|
| 407 |
+
|
| 408 |
+
// Handle capture
|
| 409 |
+
if (targetPiece) {
|
| 410 |
+
capturedPieces[piece[0] === 'w' ? 'black' : 'white'].push(targetPiece);
|
| 411 |
+
updateCapturedPieces();
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
// Handle pawn promotion (simplified)
|
| 415 |
+
if (piece[1] === 'p' && (toRow === 0 || toRow === 7)) {
|
| 416 |
+
showPromotionModal(fromRow, fromCol, toRow, toCol);
|
| 417 |
+
return;
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
// Execute the move
|
| 421 |
+
board[toRow][toCol] = piece;
|
| 422 |
+
board[fromRow][fromCol] = '';
|
| 423 |
+
|
| 424 |
+
// Add to move history
|
| 425 |
+
const moveNotation = getMoveNotation(fromRow, fromCol, toRow, toCol, targetPiece);
|
| 426 |
+
moveHistoryList.push(moveNotation);
|
| 427 |
+
updateMoveHistory();
|
| 428 |
+
|
| 429 |
+
// Switch turns
|
| 430 |
+
isWhiteTurn = !isWhiteTurn;
|
| 431 |
+
updateCurrentPlayerDisplay();
|
| 432 |
+
|
| 433 |
+
renderBoard();
|
| 434 |
+
updateGameStatus();
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
// Get algebraic notation for a move
|
| 438 |
+
function getMoveNotation(fromRow, fromCol, toRow, toCol, capturedPiece) {
|
| 439 |
+
const piece = board[fromRow][fromCol];
|
| 440 |
+
const pieceSymbol = piece[1] === 'p' ? '' : piece[1].toUpperCase();
|
| 441 |
+
const captureSymbol = capturedPiece ? 'x' : '';
|
| 442 |
+
const file = String.fromCharCode(97 + fromCol);
|
| 443 |
+
const rank = 8 - fromRow;
|
| 444 |
+
const toFile = String.fromCharCode(97 + toCol);
|
| 445 |
+
const toRank = 8 - toRow;
|
| 446 |
+
|
| 447 |
+
return `${isWhiteTurn ? 'White' : 'Black'}: ${pieceSymbol}${file}${rank}${captureSymbol}${toFile}${toRank}`;
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
// Update move history display
|
| 451 |
+
function updateMoveHistory() {
|
| 452 |
+
moveHistory.innerHTML = '';
|
| 453 |
+
moveHistoryList.forEach((move, index) => {
|
| 454 |
+
const moveElement = document.createElement('div');
|
| 455 |
+
moveElement.textContent = `${index + 1}. ${move}`;
|
| 456 |
+
moveHistory.appendChild(moveElement);
|
| 457 |
+
});
|
| 458 |
+
|
| 459 |
+
// Scroll to bottom
|
| 460 |
+
moveHistory.scrollTop = moveHistory.scrollHeight;
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
// Update captured pieces display
|
| 464 |
+
function updateCapturedPieces() {
|
| 465 |
+
whiteCaptured.innerHTML = '';
|
| 466 |
+
blackCaptured.innerHTML = '';
|
| 467 |
+
|
| 468 |
+
capturedPieces.white.forEach(piece => {
|
| 469 |
+
const pieceElement = document.createElement('div');
|
| 470 |
+
pieceElement.className = 'captured-piece';
|
| 471 |
+
pieceElement.style.backgroundImage = `url('http://static.photos/chess/white/200x200/${piece[1]})`;
|
| 472 |
+
whiteCaptured.appendChild(pieceElement);
|
| 473 |
+
});
|
| 474 |
+
|
| 475 |
+
capturedPieces.black.forEach(piece => {
|
| 476 |
+
const pieceElement = document.createElement('div');
|
| 477 |
+
pieceElement.className = 'captured-piece';
|
| 478 |
+
pieceElement.style.backgroundImage = `url('http://static.photos/chess/black/200x200/${piece[1]})`;
|
| 479 |
+
blackCaptured.appendChild(pieceElement);
|
| 480 |
+
});
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
// Update game status display
|
| 484 |
+
function updateGameStatus() {
|
| 485 |
+
// Simplified status - a real implementation would check for check, checkmate, etc.
|
| 486 |
+
gameStatus.textContent = isWhiteTurn ? "White's turn" : "Black's turn";
|
| 487 |
+
gameStatus.className = 'bg-gray-700 p-3 rounded';
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
// Update current player display
|
| 491 |
+
function updateCurrentPlayerDisplay() {
|
| 492 |
+
currentPlayer.innerHTML = isWhiteTurn ?
|
| 493 |
+
'<div class="w-6 h-6 bg-white rounded-full mr-2"></div> White' :
|
| 494 |
+
'<div class="w-6 h-6 bg-black border border-white rounded-full mr-2"></div> Black';
|
| 495 |
+
}
|
| 496 |
+
|
| 497 |
+
// Show promotion modal
|
| 498 |
+
function showPromotionModal(fromRow, fromCol, toRow, toCol) {
|
| 499 |
+
promotionModal.style.display = 'flex';
|
| 500 |
+
|
| 501 |
+
// Set up promotion options
|
| 502 |
+
const color = board[fromRow][fromCol][0];
|
| 503 |
+
const options = document.querySelectorAll('.promotion-piece');
|
| 504 |
+
|
| 505 |
+
options.forEach(option => {
|
| 506 |
+
const pieceType = option.dataset.piece;
|
| 507 |
+
option.style.backgroundImage = `url('http://static.photos/chess/${color}/200x200/${pieceType})`;
|
| 508 |
+
|
| 509 |
+
option.onclick = function() {
|
| 510 |
+
// Promote the pawn
|
| 511 |
+
board[toRow][toCol] = color + pieceType;
|
| 512 |
+
board[fromRow][fromCol] = '';
|
| 513 |
+
|
| 514 |
+
// Add to move history with promotion notation
|
| 515 |
+
const moveNotation = getMoveNotation(fromRow, fromCol, toRow, toCol, null) + '=' + pieceType.toUpperCase();
|
| 516 |
+
moveHistoryList.push(moveNotation);
|
| 517 |
+
updateMoveHistory();
|
| 518 |
+
|
| 519 |
+
// Switch turns
|
| 520 |
+
isWhiteTurn = !isWhiteTurn;
|
| 521 |
+
updateCurrentPlayerDisplay();
|
| 522 |
+
|
| 523 |
+
renderBoard();
|
| 524 |
+
updateGameStatus();
|
| 525 |
+
|
| 526 |
+
// Hide modal
|
| 527 |
+
promotionModal.style.display = 'none';
|
| 528 |
+
};
|
| 529 |
+
});
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
// Event listeners
|
| 533 |
+
resetBtn.addEventListener('click', initializeBoard);
|
| 534 |
+
|
| 535 |
+
undoBtn.addEventListener('click', function() {
|
| 536 |
+
if (moveHistoryList.length > 0) {
|
| 537 |
+
// Simplified undo - a real implementation would be more complex
|
| 538 |
+
alert("Undo functionality would be implemented here!");
|
| 539 |
+
}
|
| 540 |
+
});
|
| 541 |
+
|
| 542 |
+
flipBoardBtn.addEventListener('click', function() {
|
| 543 |
+
boardFlipped = !boardFlipped;
|
| 544 |
+
renderBoard();
|
| 545 |
+
});
|
| 546 |
+
|
| 547 |
+
hintBtn.addEventListener('click', function() {
|
| 548 |
+
if (selectedPiece) {
|
| 549 |
+
// Already showing hints
|
| 550 |
+
return;
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
// Find a piece with legal moves
|
| 554 |
+
for (let row = 0; row < 8; row++) {
|
| 555 |
+
for (let col = 0; col < 8; col++) {
|
| 556 |
+
const piece = board[row][col];
|
| 557 |
+
if (piece && piece[0] === (isWhiteTurn ? 'w' : 'b')) {
|
| 558 |
+
const moves = calculateLegalMoves(row, col);
|
| 559 |
+
if (moves.length > 0) {
|
| 560 |
+
selectPiece(row, col);
|
| 561 |
+
return;
|
| 562 |
+
}
|
| 563 |
+
}
|
| 564 |
+
}
|
| 565 |
+
}
|
| 566 |
+
});
|
| 567 |
+
|
| 568 |
+
// Initialize the game
|
| 569 |
+
initializeBoard();
|
| 570 |
+
});
|
| 571 |
+
</script>
|
| 572 |
+
</body>
|
| 573 |
</html>
|