Update index.html
Browse files- index.html +118 -49
index.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>Arcane
|
| 7 |
|
| 8 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chessboard-js/1.0.0/chessboard-1.0.0.min.css">
|
| 9 |
|
|
@@ -12,7 +12,8 @@
|
|
| 12 |
--bg-color: #212121;
|
| 13 |
--text-color: #e0e0e0;
|
| 14 |
--accent-color: #4caf50;
|
| 15 |
-
--highlight: #00e5ff;
|
|
|
|
| 16 |
--panel-bg: #333;
|
| 17 |
}
|
| 18 |
|
|
@@ -26,6 +27,7 @@
|
|
| 26 |
margin: 0;
|
| 27 |
padding: 10px;
|
| 28 |
user-select: none;
|
|
|
|
| 29 |
}
|
| 30 |
|
| 31 |
h1 { margin-bottom: 10px; text-align: center; font-size: 1.5rem; }
|
|
@@ -52,13 +54,19 @@
|
|
| 52 |
align-items: center;
|
| 53 |
justify-content: center;
|
| 54 |
color: #777;
|
|
|
|
| 55 |
}
|
| 56 |
|
| 57 |
-
/* --- HIGHLIGHT
|
| 58 |
.highlight-best {
|
| 59 |
box-shadow: inset 0 0 3px 3px var(--highlight) !important;
|
| 60 |
background-color: rgba(0, 229, 255, 0.3) !important;
|
| 61 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
/* --- TURN SWITCHER UI --- */
|
| 64 |
.turn-controls {
|
|
@@ -118,7 +126,6 @@
|
|
| 118 |
overflow: hidden;
|
| 119 |
}
|
| 120 |
|
| 121 |
-
/* Loading Bar Animation */
|
| 122 |
.loading-bar {
|
| 123 |
position: absolute;
|
| 124 |
bottom: 0;
|
|
@@ -153,14 +160,12 @@
|
|
| 153 |
button:active { transform: scale(0.98); }
|
| 154 |
#flipBtn { background-color: #008CBA; }
|
| 155 |
|
| 156 |
-
/* Error Log */
|
| 157 |
#debug-log { display:none; color:red; background:#300; padding:10px; width:100%; font-size:12px;}
|
| 158 |
-
|
| 159 |
</style>
|
| 160 |
</head>
|
| 161 |
<body>
|
| 162 |
|
| 163 |
-
<h1>⚡ Arcane
|
| 164 |
|
| 165 |
<div id="debug-log"></div>
|
| 166 |
|
|
@@ -210,6 +215,7 @@
|
|
| 210 |
|
| 211 |
const STOCKFISH_PATH = 'https://cdnjs.cloudflare.com/ajax/libs/stockfish.js/10.0.0/stockfish.js';
|
| 212 |
let board, game, engine;
|
|
|
|
| 213 |
|
| 214 |
$(document).ready(function() { initGame(); });
|
| 215 |
|
|
@@ -217,7 +223,7 @@
|
|
| 217 |
game = new Chess();
|
| 218 |
|
| 219 |
const config = {
|
| 220 |
-
draggable: true,
|
| 221 |
position: 'start',
|
| 222 |
onDragStart: onDragStart,
|
| 223 |
onDrop: onDrop,
|
|
@@ -229,12 +235,62 @@
|
|
| 229 |
board = Chessboard('board', config);
|
| 230 |
$(window).resize(board.resize);
|
| 231 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
initStockfish();
|
| 233 |
updateUI();
|
| 234 |
}
|
| 235 |
|
| 236 |
-
// ---
|
| 237 |
-
function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
$('#board .square-55d63').removeClass('highlight-best');
|
| 239 |
let source = move.substring(0, 2);
|
| 240 |
let target = move.substring(2, 4);
|
|
@@ -242,10 +298,48 @@
|
|
| 242 |
$('#board .square-' + target).addClass('highlight-best');
|
| 243 |
}
|
| 244 |
|
| 245 |
-
function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
$('#board .square-55d63').removeClass('highlight-best');
|
| 247 |
}
|
| 248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
// --- TURN LOGIC ---
|
| 250 |
function forceTurn(color) {
|
| 251 |
if (game.turn() === color) return;
|
|
@@ -256,6 +350,8 @@
|
|
| 256 |
let newFen = parts.join(' ');
|
| 257 |
if(game.load(newFen)) {
|
| 258 |
board.position(newFen);
|
|
|
|
|
|
|
| 259 |
updateUI();
|
| 260 |
analyzePosition();
|
| 261 |
}
|
|
@@ -299,13 +395,12 @@
|
|
| 299 |
let moves = matchPv[1].split(' ');
|
| 300 |
let bestMove = moves[0];
|
| 301 |
$('#best-move').html(`➜ ${bestMove}`);
|
| 302 |
-
|
| 303 |
}
|
| 304 |
}
|
| 305 |
|
| 306 |
-
// Detect when engine is done (bestmove command)
|
| 307 |
if (line.startsWith('bestmove')) {
|
| 308 |
-
$('#loading-bar').css('width', '0%');
|
| 309 |
$('#engineStatus').text('Done');
|
| 310 |
}
|
| 311 |
};
|
|
@@ -317,64 +412,38 @@
|
|
| 317 |
}
|
| 318 |
|
| 319 |
function analyzePosition() {
|
| 320 |
-
// Visual Reset
|
| 321 |
$('#best-move').text('...');
|
| 322 |
-
|
| 323 |
$('#engineStatus').text('Thinking...');
|
| 324 |
-
|
| 325 |
-
// Start Loading Bar Animation
|
| 326 |
$('#loading-bar').css('width', '0%').animate({width: '100%'}, 2000);
|
| 327 |
|
| 328 |
if(engine) {
|
| 329 |
engine.postMessage(`position fen ${game.fen()}`);
|
| 330 |
-
|
| 331 |
-
// --- THE SPEED FIX ---
|
| 332 |
-
// "movetime 2000" means: Think for exactly 2000 milliseconds (2 seconds)
|
| 333 |
engine.postMessage('go movetime 2000');
|
| 334 |
}
|
| 335 |
}
|
| 336 |
|
| 337 |
-
// --- GAME MOVEMENT ---
|
| 338 |
-
function onDragStart(source, piece) {
|
| 339 |
-
if (game.game_over()) return false;
|
| 340 |
-
if ((game.turn() === 'w' && piece.search(/^b/) !== -1) ||
|
| 341 |
-
(game.turn() === 'b' && piece.search(/^w/) !== -1)) {
|
| 342 |
-
return false;
|
| 343 |
-
}
|
| 344 |
-
}
|
| 345 |
-
|
| 346 |
-
function onDrop(source, target) {
|
| 347 |
-
const move = game.move({
|
| 348 |
-
from: source,
|
| 349 |
-
to: target,
|
| 350 |
-
promotion: 'q'
|
| 351 |
-
});
|
| 352 |
-
|
| 353 |
-
if (move === null) return 'snapback';
|
| 354 |
-
|
| 355 |
-
updateUI();
|
| 356 |
-
analyzePosition();
|
| 357 |
-
}
|
| 358 |
-
|
| 359 |
-
function onSnapEnd() {
|
| 360 |
-
board.position(game.fen());
|
| 361 |
-
}
|
| 362 |
-
|
| 363 |
$('#resetBtn').click(function() {
|
| 364 |
game.reset();
|
| 365 |
board.start();
|
|
|
|
| 366 |
$('#best-move').text('...');
|
| 367 |
$('#eval-score').text('0.00');
|
| 368 |
-
|
|
|
|
| 369 |
updateUI();
|
| 370 |
});
|
| 371 |
|
| 372 |
$('#flipBtn').click(function() {
|
| 373 |
board.flip();
|
|
|
|
| 374 |
let currentText = $('#best-move').text();
|
| 375 |
if(currentText.includes('➜')) {
|
| 376 |
let move = currentText.replace('➜ ', '');
|
| 377 |
-
|
|
|
|
|
|
|
|
|
|
| 378 |
}
|
| 379 |
});
|
| 380 |
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Arcane Touch 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 |
|
|
|
|
| 12 |
--bg-color: #212121;
|
| 13 |
--text-color: #e0e0e0;
|
| 14 |
--accent-color: #4caf50;
|
| 15 |
+
--highlight: #00e5ff; /* Cyan for Best Move */
|
| 16 |
+
--selected: #ffeb3b; /* Yellow for Selected Piece */
|
| 17 |
--panel-bg: #333;
|
| 18 |
}
|
| 19 |
|
|
|
|
| 27 |
margin: 0;
|
| 28 |
padding: 10px;
|
| 29 |
user-select: none;
|
| 30 |
+
-webkit-tap-highlight-color: transparent; /* Removes blue tap box on Android */
|
| 31 |
}
|
| 32 |
|
| 33 |
h1 { margin-bottom: 10px; text-align: center; font-size: 1.5rem; }
|
|
|
|
| 54 |
align-items: center;
|
| 55 |
justify-content: center;
|
| 56 |
color: #777;
|
| 57 |
+
touch-action: none; /* Prevents scrolling while touching board */
|
| 58 |
}
|
| 59 |
|
| 60 |
+
/* --- HIGHLIGHT CLASSES --- */
|
| 61 |
.highlight-best {
|
| 62 |
box-shadow: inset 0 0 3px 3px var(--highlight) !important;
|
| 63 |
background-color: rgba(0, 229, 255, 0.3) !important;
|
| 64 |
}
|
| 65 |
+
|
| 66 |
+
.highlight-selected {
|
| 67 |
+
box-shadow: inset 0 0 3px 3px var(--selected) !important;
|
| 68 |
+
background-color: rgba(255, 235, 59, 0.4) !important;
|
| 69 |
+
}
|
| 70 |
|
| 71 |
/* --- TURN SWITCHER UI --- */
|
| 72 |
.turn-controls {
|
|
|
|
| 126 |
overflow: hidden;
|
| 127 |
}
|
| 128 |
|
|
|
|
| 129 |
.loading-bar {
|
| 130 |
position: absolute;
|
| 131 |
bottom: 0;
|
|
|
|
| 160 |
button:active { transform: scale(0.98); }
|
| 161 |
#flipBtn { background-color: #008CBA; }
|
| 162 |
|
|
|
|
| 163 |
#debug-log { display:none; color:red; background:#300; padding:10px; width:100%; font-size:12px;}
|
|
|
|
| 164 |
</style>
|
| 165 |
</head>
|
| 166 |
<body>
|
| 167 |
|
| 168 |
+
<h1>⚡ Arcane Touch Analyzer</h1>
|
| 169 |
|
| 170 |
<div id="debug-log"></div>
|
| 171 |
|
|
|
|
| 215 |
|
| 216 |
const STOCKFISH_PATH = 'https://cdnjs.cloudflare.com/ajax/libs/stockfish.js/10.0.0/stockfish.js';
|
| 217 |
let board, game, engine;
|
| 218 |
+
let selectedSquare = null; // Track tap moves
|
| 219 |
|
| 220 |
$(document).ready(function() { initGame(); });
|
| 221 |
|
|
|
|
| 223 |
game = new Chess();
|
| 224 |
|
| 225 |
const config = {
|
| 226 |
+
draggable: true, // Keep drag enabled
|
| 227 |
position: 'start',
|
| 228 |
onDragStart: onDragStart,
|
| 229 |
onDrop: onDrop,
|
|
|
|
| 235 |
board = Chessboard('board', config);
|
| 236 |
$(window).resize(board.resize);
|
| 237 |
|
| 238 |
+
// --- TAP TO MOVE LISTENER ---
|
| 239 |
+
// We listen for clicks on squares (class starts with square-)
|
| 240 |
+
$('#board').on('click', '[class^="square-"]', onSquareClick);
|
| 241 |
+
|
| 242 |
initStockfish();
|
| 243 |
updateUI();
|
| 244 |
}
|
| 245 |
|
| 246 |
+
// --- TAP TO MOVE LOGIC ---
|
| 247 |
+
function onSquareClick() {
|
| 248 |
+
// Get the square ID (e.g., 'e2') from the data attribute
|
| 249 |
+
const square = $(this).attr('data-square');
|
| 250 |
+
const piece = game.get(square);
|
| 251 |
+
const turn = game.turn();
|
| 252 |
+
|
| 253 |
+
// 1. If nothing is selected yet
|
| 254 |
+
if (selectedSquare === null) {
|
| 255 |
+
// Only select if it's a piece of the current turn's color
|
| 256 |
+
if (piece && piece.color === turn) {
|
| 257 |
+
selectedSquare = square;
|
| 258 |
+
highlightSelected(square);
|
| 259 |
+
}
|
| 260 |
+
return;
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
// 2. If something IS selected, try to move there
|
| 264 |
+
const move = game.move({
|
| 265 |
+
from: selectedSquare,
|
| 266 |
+
to: square,
|
| 267 |
+
promotion: 'q' // Always promote to queen for simplicity
|
| 268 |
+
});
|
| 269 |
+
|
| 270 |
+
// If move is valid
|
| 271 |
+
if (move) {
|
| 272 |
+
board.position(game.fen());
|
| 273 |
+
selectedSquare = null;
|
| 274 |
+
removeSelectionHighlights();
|
| 275 |
+
updateUI();
|
| 276 |
+
analyzePosition();
|
| 277 |
+
}
|
| 278 |
+
// If move is invalid
|
| 279 |
+
else {
|
| 280 |
+
// If they clicked a piece of their own color, switch selection
|
| 281 |
+
if (piece && piece.color === turn) {
|
| 282 |
+
selectedSquare = square;
|
| 283 |
+
highlightSelected(square);
|
| 284 |
+
} else {
|
| 285 |
+
// Clicked empty square or enemy piece (but invalid move) -> Deselect
|
| 286 |
+
selectedSquare = null;
|
| 287 |
+
removeSelectionHighlights();
|
| 288 |
+
}
|
| 289 |
+
}
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
// --- VISUAL HIGHLIGHTS ---
|
| 293 |
+
function highlightBestMove(move) {
|
| 294 |
$('#board .square-55d63').removeClass('highlight-best');
|
| 295 |
let source = move.substring(0, 2);
|
| 296 |
let target = move.substring(2, 4);
|
|
|
|
| 298 |
$('#board .square-' + target).addClass('highlight-best');
|
| 299 |
}
|
| 300 |
|
| 301 |
+
function highlightSelected(square) {
|
| 302 |
+
removeSelectionHighlights();
|
| 303 |
+
$('#board .square-' + square).addClass('highlight-selected');
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
function removeSelectionHighlights() {
|
| 307 |
+
$('#board .square-55d63').removeClass('highlight-selected');
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
function removeBestHighlights() {
|
| 311 |
$('#board .square-55d63').removeClass('highlight-best');
|
| 312 |
}
|
| 313 |
|
| 314 |
+
// --- DRAG LOGIC (Keep sync with Tap) ---
|
| 315 |
+
function onDragStart(source, piece) {
|
| 316 |
+
if (game.game_over()) return false;
|
| 317 |
+
if ((game.turn() === 'w' && piece.search(/^b/) !== -1) ||
|
| 318 |
+
(game.turn() === 'b' && piece.search(/^w/) !== -1)) {
|
| 319 |
+
return false;
|
| 320 |
+
}
|
| 321 |
+
// If dragging, clear any tap selection
|
| 322 |
+
selectedSquare = null;
|
| 323 |
+
removeSelectionHighlights();
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
function onDrop(source, target) {
|
| 327 |
+
const move = game.move({
|
| 328 |
+
from: source,
|
| 329 |
+
to: target,
|
| 330 |
+
promotion: 'q'
|
| 331 |
+
});
|
| 332 |
+
|
| 333 |
+
if (move === null) return 'snapback';
|
| 334 |
+
|
| 335 |
+
updateUI();
|
| 336 |
+
analyzePosition();
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
function onSnapEnd() {
|
| 340 |
+
board.position(game.fen());
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
// --- TURN LOGIC ---
|
| 344 |
function forceTurn(color) {
|
| 345 |
if (game.turn() === color) return;
|
|
|
|
| 350 |
let newFen = parts.join(' ');
|
| 351 |
if(game.load(newFen)) {
|
| 352 |
board.position(newFen);
|
| 353 |
+
selectedSquare = null;
|
| 354 |
+
removeSelectionHighlights();
|
| 355 |
updateUI();
|
| 356 |
analyzePosition();
|
| 357 |
}
|
|
|
|
| 395 |
let moves = matchPv[1].split(' ');
|
| 396 |
let bestMove = moves[0];
|
| 397 |
$('#best-move').html(`➜ ${bestMove}`);
|
| 398 |
+
highlightBestMove(bestMove);
|
| 399 |
}
|
| 400 |
}
|
| 401 |
|
|
|
|
| 402 |
if (line.startsWith('bestmove')) {
|
| 403 |
+
$('#loading-bar').css('width', '0%');
|
| 404 |
$('#engineStatus').text('Done');
|
| 405 |
}
|
| 406 |
};
|
|
|
|
| 412 |
}
|
| 413 |
|
| 414 |
function analyzePosition() {
|
|
|
|
| 415 |
$('#best-move').text('...');
|
| 416 |
+
removeBestHighlights();
|
| 417 |
$('#engineStatus').text('Thinking...');
|
|
|
|
|
|
|
| 418 |
$('#loading-bar').css('width', '0%').animate({width: '100%'}, 2000);
|
| 419 |
|
| 420 |
if(engine) {
|
| 421 |
engine.postMessage(`position fen ${game.fen()}`);
|
|
|
|
|
|
|
|
|
|
| 422 |
engine.postMessage('go movetime 2000');
|
| 423 |
}
|
| 424 |
}
|
| 425 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
$('#resetBtn').click(function() {
|
| 427 |
game.reset();
|
| 428 |
board.start();
|
| 429 |
+
selectedSquare = null;
|
| 430 |
$('#best-move').text('...');
|
| 431 |
$('#eval-score').text('0.00');
|
| 432 |
+
removeSelectionHighlights();
|
| 433 |
+
removeBestHighlights();
|
| 434 |
updateUI();
|
| 435 |
});
|
| 436 |
|
| 437 |
$('#flipBtn').click(function() {
|
| 438 |
board.flip();
|
| 439 |
+
// Re-apply highlights after flip because DOM is redrawn
|
| 440 |
let currentText = $('#best-move').text();
|
| 441 |
if(currentText.includes('➜')) {
|
| 442 |
let move = currentText.replace('➜ ', '');
|
| 443 |
+
highlightBestMove(move);
|
| 444 |
+
}
|
| 445 |
+
if(selectedSquare) {
|
| 446 |
+
highlightSelected(selectedSquare);
|
| 447 |
}
|
| 448 |
});
|
| 449 |
|