Update index.html
Browse files- index.html +51 -23
index.html
CHANGED
|
@@ -23,35 +23,43 @@
|
|
| 23 |
flex-direction: column;
|
| 24 |
align-items: center;
|
| 25 |
margin: 0;
|
| 26 |
-
padding:
|
| 27 |
}
|
| 28 |
|
| 29 |
-
h1 { margin-bottom: 20px; }
|
| 30 |
|
| 31 |
.container {
|
| 32 |
display: flex;
|
| 33 |
-
flex-
|
| 34 |
gap: 20px;
|
| 35 |
justify-content: center;
|
|
|
|
| 36 |
max-width: 900px;
|
| 37 |
width: 100%;
|
| 38 |
}
|
| 39 |
|
| 40 |
-
/* FORCE BOARD
|
| 41 |
#board {
|
| 42 |
width: 100%;
|
| 43 |
-
max-width: 400px;
|
|
|
|
| 44 |
margin: 0 auto;
|
| 45 |
-
/*
|
| 46 |
-
border: 2px solid #555;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
}
|
| 48 |
|
| 49 |
.panel {
|
| 50 |
-
|
| 51 |
-
|
| 52 |
background: var(--panel-bg);
|
| 53 |
padding: 20px;
|
| 54 |
border-radius: 8px;
|
|
|
|
| 55 |
display: flex;
|
| 56 |
flex-direction: column;
|
| 57 |
gap: 15px;
|
|
@@ -71,13 +79,15 @@
|
|
| 71 |
.controls { display: flex; gap: 10px; margin-top: auto; }
|
| 72 |
|
| 73 |
button {
|
| 74 |
-
|
|
|
|
| 75 |
border: none;
|
| 76 |
border-radius: 4px;
|
| 77 |
cursor: pointer;
|
| 78 |
font-weight: bold;
|
| 79 |
color: white;
|
| 80 |
background-color: #555;
|
|
|
|
| 81 |
}
|
| 82 |
button:hover { opacity: 0.9; }
|
| 83 |
#flipBtn { background-color: var(--accent-color); }
|
|
@@ -100,12 +110,12 @@
|
|
| 100 |
<h1>♟️ Arcane Chess Analyzer</h1>
|
| 101 |
|
| 102 |
<div class="container">
|
| 103 |
-
<div id="board"></div>
|
| 104 |
|
| 105 |
<div class="panel">
|
| 106 |
<div style="display: flex; align-items: center; justify-content: space-between;">
|
| 107 |
<h3>Engine Analysis</h3>
|
| 108 |
-
<div><span id="engineStatus" class="status-indicator"></span><span id="engineText">
|
| 109 |
</div>
|
| 110 |
|
| 111 |
<div class="stats-box">
|
|
@@ -115,7 +125,7 @@
|
|
| 115 |
|
| 116 |
<div class="stats-box">
|
| 117 |
<span class="stats-label">Best Move Sequence</span>
|
| 118 |
-
<span class="stats-value" id="best-line">
|
| 119 |
</div>
|
| 120 |
|
| 121 |
<div class="stats-box">
|
|
@@ -150,34 +160,49 @@
|
|
| 150 |
const $engineText = $('#engineText');
|
| 151 |
|
| 152 |
function initGame() {
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
| 154 |
const config = {
|
| 155 |
draggable: true,
|
| 156 |
position: 'start',
|
| 157 |
onDragStart: onDragStart,
|
| 158 |
onDrop: onDrop,
|
| 159 |
onSnapEnd: onSnapEnd,
|
|
|
|
| 160 |
pieceTheme: 'https://chessboardjs.com/img/chesspieces/wikipedia/{piece}.png'
|
| 161 |
};
|
| 162 |
|
| 163 |
-
//
|
|
|
|
|
|
|
| 164 |
board = Chessboard('board', config);
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
-
//
|
| 167 |
initStockfish();
|
| 168 |
updateStatus();
|
| 169 |
|
| 170 |
-
// Handle window resize
|
| 171 |
$(window).resize(board.resize);
|
| 172 |
}
|
| 173 |
|
| 174 |
-
// --- ENGINE LOGIC ---
|
| 175 |
function initStockfish() {
|
| 176 |
try {
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
engine.onmessage = function(event) {
|
| 180 |
const line = event.data;
|
|
|
|
| 181 |
|
| 182 |
if (line === 'uciok') {
|
| 183 |
$engineStatus.addClass('ready');
|
|
@@ -208,8 +233,8 @@
|
|
| 208 |
engine.postMessage('uci');
|
| 209 |
engine.postMessage('isready');
|
| 210 |
} catch (e) {
|
| 211 |
-
$engineText.text('Engine Error
|
| 212 |
-
console.error(e);
|
| 213 |
}
|
| 214 |
}
|
| 215 |
|
|
@@ -273,8 +298,11 @@
|
|
| 273 |
|
| 274 |
$('#flipBtn').on('click', board.flip);
|
| 275 |
|
| 276 |
-
// Start
|
| 277 |
-
$(document).ready(
|
|
|
|
|
|
|
|
|
|
| 278 |
</script>
|
| 279 |
</body>
|
| 280 |
</html>
|
|
|
|
| 23 |
flex-direction: column;
|
| 24 |
align-items: center;
|
| 25 |
margin: 0;
|
| 26 |
+
padding: 10px; /* Reduced padding for mobile */
|
| 27 |
}
|
| 28 |
|
| 29 |
+
h1 { margin-bottom: 20px; text-align: center; }
|
| 30 |
|
| 31 |
.container {
|
| 32 |
display: flex;
|
| 33 |
+
flex-direction: column; /* Stack vertically on mobile */
|
| 34 |
gap: 20px;
|
| 35 |
justify-content: center;
|
| 36 |
+
align-items: center;
|
| 37 |
max-width: 900px;
|
| 38 |
width: 100%;
|
| 39 |
}
|
| 40 |
|
| 41 |
+
/* --- FORCE BOARD VISIBILITY --- */
|
| 42 |
#board {
|
| 43 |
width: 100%;
|
| 44 |
+
max-width: 400px; /* Max size for desktop */
|
| 45 |
+
aspect-ratio: 1 / 1; /* Forces it to be a square */
|
| 46 |
margin: 0 auto;
|
| 47 |
+
background-color: #303030; /* Dark grey placeholder */
|
| 48 |
+
border: 2px solid #555;
|
| 49 |
+
display: flex;
|
| 50 |
+
align-items: center;
|
| 51 |
+
justify-content: center;
|
| 52 |
+
color: #777;
|
| 53 |
+
position: relative; /* Context for pieces */
|
| 54 |
}
|
| 55 |
|
| 56 |
.panel {
|
| 57 |
+
width: 100%;
|
| 58 |
+
max-width: 400px; /* Match board width */
|
| 59 |
background: var(--panel-bg);
|
| 60 |
padding: 20px;
|
| 61 |
border-radius: 8px;
|
| 62 |
+
box-sizing: border-box; /* Ensures padding doesn't break width */
|
| 63 |
display: flex;
|
| 64 |
flex-direction: column;
|
| 65 |
gap: 15px;
|
|
|
|
| 79 |
.controls { display: flex; gap: 10px; margin-top: auto; }
|
| 80 |
|
| 81 |
button {
|
| 82 |
+
flex: 1; /* Make buttons even width */
|
| 83 |
+
padding: 12px;
|
| 84 |
border: none;
|
| 85 |
border-radius: 4px;
|
| 86 |
cursor: pointer;
|
| 87 |
font-weight: bold;
|
| 88 |
color: white;
|
| 89 |
background-color: #555;
|
| 90 |
+
font-size: 16px; /* Better touch target */
|
| 91 |
}
|
| 92 |
button:hover { opacity: 0.9; }
|
| 93 |
#flipBtn { background-color: var(--accent-color); }
|
|
|
|
| 110 |
<h1>♟️ Arcane Chess Analyzer</h1>
|
| 111 |
|
| 112 |
<div class="container">
|
| 113 |
+
<div id="board">Loading Board...</div>
|
| 114 |
|
| 115 |
<div class="panel">
|
| 116 |
<div style="display: flex; align-items: center; justify-content: space-between;">
|
| 117 |
<h3>Engine Analysis</h3>
|
| 118 |
+
<div><span id="engineStatus" class="status-indicator"></span><span id="engineText">Initializing...</span></div>
|
| 119 |
</div>
|
| 120 |
|
| 121 |
<div class="stats-box">
|
|
|
|
| 125 |
|
| 126 |
<div class="stats-box">
|
| 127 |
<span class="stats-label">Best Move Sequence</span>
|
| 128 |
+
<span class="stats-value" id="best-line">Waiting for engine...</span>
|
| 129 |
</div>
|
| 130 |
|
| 131 |
<div class="stats-box">
|
|
|
|
| 160 |
const $engineText = $('#engineText');
|
| 161 |
|
| 162 |
function initGame() {
|
| 163 |
+
console.log("Initializing Game...");
|
| 164 |
+
|
| 165 |
+
// 1. CONFIGURE BOARD
|
| 166 |
+
// We use a responsive width calculation
|
| 167 |
const config = {
|
| 168 |
draggable: true,
|
| 169 |
position: 'start',
|
| 170 |
onDragStart: onDragStart,
|
| 171 |
onDrop: onDrop,
|
| 172 |
onSnapEnd: onSnapEnd,
|
| 173 |
+
// FORCE PIECE IMAGES FROM WIKIPEDIA
|
| 174 |
pieceTheme: 'https://chessboardjs.com/img/chesspieces/wikipedia/{piece}.png'
|
| 175 |
};
|
| 176 |
|
| 177 |
+
// 2. CREATE BOARD
|
| 178 |
+
// We empty the div first to remove "Loading Board..." text
|
| 179 |
+
$('#board').empty();
|
| 180 |
board = Chessboard('board', config);
|
| 181 |
+
|
| 182 |
+
// Force a resize calculation to ensure pieces appear
|
| 183 |
+
setTimeout(() => { board.resize(); }, 200);
|
| 184 |
|
| 185 |
+
// 3. START ENGINE
|
| 186 |
initStockfish();
|
| 187 |
updateStatus();
|
| 188 |
|
| 189 |
+
// Handle window resize
|
| 190 |
$(window).resize(board.resize);
|
| 191 |
}
|
| 192 |
|
| 193 |
+
// --- ENGINE LOGIC (BLOB FIX) ---
|
| 194 |
function initStockfish() {
|
| 195 |
try {
|
| 196 |
+
// THE BLOB FIX: Creates a local URL for the worker
|
| 197 |
+
// This bypasses the security restriction on Hugging Face Spaces
|
| 198 |
+
const blob = new Blob([`importScripts('${STOCKFISH_PATH}')`], {type: 'application/javascript'});
|
| 199 |
+
const url = URL.createObjectURL(blob);
|
| 200 |
+
|
| 201 |
+
engine = new Worker(url);
|
| 202 |
|
| 203 |
engine.onmessage = function(event) {
|
| 204 |
const line = event.data;
|
| 205 |
+
console.log("Engine:", line);
|
| 206 |
|
| 207 |
if (line === 'uciok') {
|
| 208 |
$engineStatus.addClass('ready');
|
|
|
|
| 233 |
engine.postMessage('uci');
|
| 234 |
engine.postMessage('isready');
|
| 235 |
} catch (e) {
|
| 236 |
+
$engineText.text('Engine Error');
|
| 237 |
+
console.error("Engine Init Failed:", e);
|
| 238 |
}
|
| 239 |
}
|
| 240 |
|
|
|
|
| 298 |
|
| 299 |
$('#flipBtn').on('click', board.flip);
|
| 300 |
|
| 301 |
+
// Start when document is ready
|
| 302 |
+
$(document).ready(function() {
|
| 303 |
+
// Small delay to ensure container is rendered
|
| 304 |
+
setTimeout(initGame, 100);
|
| 305 |
+
});
|
| 306 |
</script>
|
| 307 |
</body>
|
| 308 |
</html>
|