api-ix commited on
Commit
8d33b1b
·
verified ·
1 Parent(s): cdd8522

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +89 -47
index.html CHANGED
@@ -5,7 +5,7 @@
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Arcane Chess Analyzer</title>
7
 
8
- <link rel="stylesheet" href="https://unpkg.com/@chrisoakman/chessboardjs@1.0.0/dist/chessboard-1.0.0.min.css">
9
 
10
  <style>
11
  :root {
@@ -23,14 +23,14 @@
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;
@@ -38,28 +38,41 @@
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,7 +92,7 @@
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;
@@ -87,7 +100,7 @@
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); }
@@ -109,8 +122,15 @@
109
 
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;">
@@ -140,61 +160,74 @@
140
  </div>
141
  </div>
142
 
143
- <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
144
- <script src="https://unpkg.com/@chrisoakman/chessboardjs@1.0.0/dist/chessboard-1.0.0.min.js"></script>
145
  <script src="https://cdnjs.cloudflare.com/ajax/libs/chess.js/0.10.3/chess.min.js"></script>
 
146
 
147
  <script>
 
 
 
 
 
 
 
 
148
  // --- CONFIGURATION ---
149
  const STOCKFISH_PATH = 'https://cdnjs.cloudflare.com/ajax/libs/stockfish.js/10.0.0/stockfish.js';
150
 
151
  let board = null;
152
- let game = new Chess();
153
  let engine = null;
154
 
155
  // UI Selectors
156
- const $status = $('#gameStatus');
157
- const $evaluation = $('#evaluation');
158
- const $bestLine = $('#best-line');
159
- const $engineStatus = $('#engineStatus');
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
 
@@ -202,7 +235,6 @@
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');
@@ -234,7 +266,7 @@
234
  engine.postMessage('isready');
235
  } catch (e) {
236
  $engineText.text('Engine Error');
237
- console.error("Engine Init Failed:", e);
238
  }
239
  }
240
 
@@ -288,20 +320,30 @@
288
  $status.text(status);
289
  }
290
 
291
- $('#resetBtn').on('click', function() {
292
- game.reset();
293
- board.start();
294
- $bestLine.text('...');
295
- $evaluation.text('0.00');
296
- updateStatus();
297
- });
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>
 
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Arcane Chess Analyzer</title>
7
 
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chessboard-js/1.0.0/chessboard-1.0.0.min.css">
9
 
10
  <style>
11
  :root {
 
23
  flex-direction: column;
24
  align-items: center;
25
  margin: 0;
26
+ padding: 10px;
27
  }
28
 
29
  h1 { margin-bottom: 20px; text-align: center; }
30
 
31
  .container {
32
  display: flex;
33
+ flex-direction: column;
34
  gap: 20px;
35
  justify-content: center;
36
  align-items: center;
 
38
  width: 100%;
39
  }
40
 
41
+ /* DEBUG / ERROR LOG */
42
+ #debug-log {
43
+ width: 100%;
44
+ max-width: 400px;
45
+ color: #ff5252;
46
+ font-family: monospace;
47
+ font-size: 12px;
48
+ background: #2a0000;
49
+ padding: 5px;
50
+ border-radius: 4px;
51
+ display: none; /* Hidden unless error */
52
+ margin-bottom: 10px;
53
+ white-space: pre-wrap;
54
+ }
55
+
56
  #board {
57
  width: 100%;
58
+ max-width: 400px;
59
+ aspect-ratio: 1 / 1;
60
  margin: 0 auto;
61
+ background-color: #303030;
62
  border: 2px solid #555;
63
  display: flex;
64
  align-items: center;
65
  justify-content: center;
66
  color: #777;
 
67
  }
68
 
69
  .panel {
70
  width: 100%;
71
+ max-width: 400px;
72
  background: var(--panel-bg);
73
  padding: 20px;
74
  border-radius: 8px;
75
+ box-sizing: border-box;
76
  display: flex;
77
  flex-direction: column;
78
  gap: 15px;
 
92
  .controls { display: flex; gap: 10px; margin-top: auto; }
93
 
94
  button {
95
+ flex: 1;
96
  padding: 12px;
97
  border: none;
98
  border-radius: 4px;
 
100
  font-weight: bold;
101
  color: white;
102
  background-color: #555;
103
+ font-size: 16px;
104
  }
105
  button:hover { opacity: 0.9; }
106
  #flipBtn { background-color: var(--accent-color); }
 
122
 
123
  <h1>♟️ Arcane Chess Analyzer</h1>
124
 
125
+ <div id="debug-log"></div>
126
+
127
  <div class="container">
128
+ <div id="board">
129
+ <div style="text-align:center;">
130
+ Loading Libraries...<br>
131
+ <small>If this stays here, turn off Brave Shields</small>
132
+ </div>
133
+ </div>
134
 
135
  <div class="panel">
136
  <div style="display: flex; align-items: center; justify-content: space-between;">
 
160
  </div>
161
  </div>
162
 
163
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
 
164
  <script src="https://cdnjs.cloudflare.com/ajax/libs/chess.js/0.10.3/chess.min.js"></script>
165
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/chessboard-js/1.0.0/chessboard-1.0.0.min.js"></script>
166
 
167
  <script>
168
+ // GLOBAL ERROR HANDLER
169
+ window.onerror = function(msg, url, line) {
170
+ const log = document.getElementById('debug-log');
171
+ log.style.display = 'block';
172
+ log.innerHTML += `ERROR: ${msg}<br>Line: ${line}<br>Check your internet or Brave Shields.<br><br>`;
173
+ return false;
174
+ };
175
+
176
  // --- CONFIGURATION ---
177
  const STOCKFISH_PATH = 'https://cdnjs.cloudflare.com/ajax/libs/stockfish.js/10.0.0/stockfish.js';
178
 
179
  let board = null;
180
+ let game = null; // initialized in initGame
181
  let engine = null;
182
 
183
  // UI Selectors
184
+ let $status, $evaluation, $bestLine, $engineStatus, $engineText;
 
 
 
 
185
 
186
  function initGame() {
187
+ // CHECK DEPENDENCIES
188
+ if (typeof $ === 'undefined') { throw new Error("jQuery failed to load."); }
189
+ if (typeof Chess === 'undefined') { throw new Error("Chess.js failed to load."); }
190
+ if (typeof Chessboard === 'undefined') { throw new Error("Chessboard.js failed to load."); }
191
+
192
+ console.log("Libraries loaded. Starting Game...");
193
+
194
+ // Init Variables
195
+ game = new Chess();
196
+ $status = $('#gameStatus');
197
+ $evaluation = $('#evaluation');
198
+ $bestLine = $('#best-line');
199
+ $engineStatus = $('#engineStatus');
200
+ $engineText = $('#engineText');
201
 
202
  // 1. CONFIGURE BOARD
 
203
  const config = {
204
  draggable: true,
205
  position: 'start',
206
  onDragStart: onDragStart,
207
  onDrop: onDrop,
208
  onSnapEnd: onSnapEnd,
 
209
  pieceTheme: 'https://chessboardjs.com/img/chesspieces/wikipedia/{piece}.png'
210
  };
211
 
212
  // 2. CREATE BOARD
213
+ $('#board').empty(); // Clear loading text
 
214
  board = Chessboard('board', config);
215
 
216
+ // Resize fix
217
+ setTimeout(() => {
218
+ if(board) board.resize();
219
+ }, 200);
220
 
221
  // 3. START ENGINE
222
  initStockfish();
223
  updateStatus();
224
 
 
225
  $(window).resize(board.resize);
226
  }
227
 
228
+ // --- ENGINE LOGIC ---
229
  function initStockfish() {
230
  try {
 
 
231
  const blob = new Blob([`importScripts('${STOCKFISH_PATH}')`], {type: 'application/javascript'});
232
  const url = URL.createObjectURL(blob);
233
 
 
235
 
236
  engine.onmessage = function(event) {
237
  const line = event.data;
 
238
 
239
  if (line === 'uciok') {
240
  $engineStatus.addClass('ready');
 
266
  engine.postMessage('isready');
267
  } catch (e) {
268
  $engineText.text('Engine Error');
269
+ throw new Error("Engine Init: " + e.message);
270
  }
271
  }
272
 
 
320
  $status.text(status);
321
  }
322
 
323
+ // --- EVENTS ---
324
+ // We use window.onload to be absolutely sure images/scripts are done
325
+ window.addEventListener('load', function() {
326
+ try {
327
+ initGame();
328
+
329
+ // Button Listeners
330
+ document.getElementById('resetBtn').addEventListener('click', function() {
331
+ game.reset();
332
+ board.start();
333
+ document.getElementById('best-line').innerText = '...';
334
+ document.getElementById('evaluation').innerText = '0.00';
335
+ updateStatus();
336
+ });
337
+
338
+ document.getElementById('flipBtn').addEventListener('click', function() {
339
+ board.flip();
340
+ });
341
 
342
+ } catch (e) {
343
+ // This catches the errors thrown in initGame
344
+ document.getElementById('debug-log').style.display = 'block';
345
+ document.getElementById('debug-log').innerHTML += `CRITICAL: ${e.message}<br>`;
346
+ }
347
  });
348
  </script>
349
  </body>