{"id":145,"date":"2025-09-12T23:07:16","date_gmt":"2025-09-12T23:07:16","guid":{"rendered":"https:\/\/trezor.quest\/?page_id=145"},"modified":"2025-11-03T07:00:05","modified_gmt":"2025-11-03T07:00:05","slug":"home","status":"publish","type":"page","link":"https:\/\/trezor.quest\/","title":{"rendered":"Home"},"content":{"rendered":"\n\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Trezor Quest's Board - Trezor Quest<\/title>\n    <style>\n        * {\n            margin: 0;\n            padding: 0;\n            box-sizing: border-box;\n        }\n        body {\n            font-family: 'MS Sans Serif', Arial, sans-serif;\n            background-color: #008080;\n            color: #000;\n            display: flex;\n            flex-direction: column;\n            align-items: center;\n            justify-content: center;\n            min-height: 100vh;\n            padding: 20px;\n            overflow-x: hidden;\n        }\n        .game-container {\n            max-width: 600px;\n            width: 100%;\n            background-color: #c0c0c0;\n            border-style: solid;\n            border-width: 2px;\n            border-color: #ffffff #000000 #000000 #ffffff;\n            padding: 3px;\n            box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);\n        }\n        h1 {\n            text-align: center;\n            color: #fff;\n            background-color: #000080;\n            font-size: 1.2em;\n            margin: 0 0 3px 0;\n            padding: 4px;\n            text-shadow: none;\n            font-weight: bold;\n            border-style: solid;\n            border-width: 2px;\n            border-color: #0a246a #000000 #000000 #0a246a;\n        }\n        .game-info {\n            display: flex;\n            justify-content: space-between;\n            margin-bottom: 3px;\n            font-size: 0.85em;\n            padding: 8px;\n            background-color: #c0c0c0;\n            border-style: solid;\n            border-width: 2px;\n            border-color: #808080 #ffffff #ffffff #808080;\n        }\n        .turn-indicator {\n            color: #ff0000;\n            font-weight: bold;\n        }\n        .difficulty-selector {\n            display: flex;\n            align-items: center;\n            justify-content: center;\n            gap: 10px;\n            margin-bottom: 3px;\n            font-size: 0.85em;\n            padding: 8px;\n            background-color: #c0c0c0;\n            border-style: solid;\n            border-width: 2px;\n            border-color: #808080 #ffffff #ffffff #808080;\n        }\n        .difficulty-selector label {\n            color: #000;\n            font-weight: bold;\n        }\n        .difficulty-selector select {\n            padding: 3px 5px;\n            background-color: #fff;\n            color: #000;\n            border-style: solid;\n            border-width: 2px;\n            border-color: #808080 #ffffff #ffffff #808080;\n            font-family: 'MS Sans Serif', Arial, sans-serif;\n            font-size: 1em;\n            cursor: pointer;\n        }\n        .difficulty-selector select:focus {\n            outline: 1px dotted #000;\n            outline-offset: -3px;\n        }\n        .btn-small {\n            padding: 4px 12px;\n            background-color: #0000ff;\n            color: #ffffff;\n            border-style: solid;\n            border-width: 2px;\n            border-color: #6666ff #0000cc #0000cc #6666ff;\n            font-family: 'MS Sans Serif', Arial, sans-serif;\n            font-size: 1em;\n            cursor: pointer;\n            font-weight: bold;\n            outline: none;\n            -webkit-appearance: none;\n            -moz-appearance: none;\n            appearance: none;\n            transition: background-color 0.2s ease;\n        }\n        .btn-small:hover {\n            background-color: #3333ff;\n            border-color: #8888ff #0000dd #0000dd #8888ff;\n        }\n        .btn-small:active {\n            border-color: #0000cc #6666ff #6666ff #0000cc;\n            padding: 5px 11px 3px 13px;\n            background-color: #0000dd;\n        }\n        .btn-mute {\n            padding: 2px 8px;\n            background-color: #0000ff;\n            color: #ffffff;\n            border-style: solid;\n            border-width: 2px;\n            border-color: #6666ff #0000cc #0000cc #6666ff;\n            font-family: 'MS Sans Serif', Arial, sans-serif;\n            font-size: 1em;\n            cursor: pointer;\n            font-weight: bold;\n            line-height: 1;\n            outline: none;\n            -webkit-appearance: none;\n            -moz-appearance: none;\n            appearance: none;\n            transition: background-color 0.2s ease;\n        }\n        .btn-mute:hover {\n            background-color: #3333ff;\n            border-color: #8888ff #0000dd #0000dd #8888ff;\n        }\n        .btn-mute:active {\n            border-color: #0000cc #6666ff #6666ff #0000cc;\n            padding: 3px 7px 1px 9px;\n            background-color: #0000dd;\n        }\n        .btn-mute.muted {\n            color: #cccccc;\n            opacity: 0.8;\n        }\n        .chess-board {\n            display: grid;\n            grid-template-columns: repeat(8, 1fr);\n            gap: 0;\n            aspect-ratio: 1;\n            border-style: solid;\n            border-width: 3px;\n            border-color: #808080 #ffffff #ffffff #808080;\n            background-color: #000;\n            margin: 3px auto;\n            max-width: 500px;\n            width: 100%;\n            touch-action: manipulation; \n            user-select: none;\n            -webkit-user-select: none;\n            -webkit-touch-callout: none; \n        }\n        .square {\n            aspect-ratio: 1;\n            display: flex;\n            align-items: center;\n            justify-content: center;\n            cursor: pointer;\n            position: relative;\n            transition: all 0.2s ease;\n            -webkit-tap-highlight-color: rgba(255, 170, 0, 0.4);\n            -webkit-touch-callout: none;\n        }\n        .square.light {\n            background-color: #f0d9b5;\n        }\n        .square.dark {\n            background-color: #b58863;\n        }\n        .square.selected {\n            box-shadow: inset 0 0 0 3px #ffaa00;\n            background-color: rgba(255, 170, 0, 0.3) !important;\n        }\n        .square.valid-move {\n            background-color: rgba(0, 255, 65, 0.3) !important;\n        }\n        .square.valid-move::after {\n            content: '';\n            width: 30%;\n            height: 30%;\n            background-color: rgba(0, 255, 65, 0.6);\n            border-radius: 50%;\n            position: absolute;\n        }\n        .square.valid-capture::after {\n            content: '';\n            position: absolute;\n            inset: 5%;\n            border: 3px solid rgba(255, 0, 0, 0.7);\n            border-radius: 50%;\n        }\n        .square.valid-castle::after {\n            content: '\u265c';\n            font-size: 1.5em;\n            color: rgba(0, 128, 255, 0.7);\n            position: absolute;\n        }\n        .piece {\n            font-size: 2em;\n            cursor: grab;\n            user-select: none;\n            -webkit-user-select: none;\n            -moz-user-select: none;\n            -ms-user-select: none;\n            transition: transform 0.2s ease;\n            filter: drop-shadow(2px 2px 2px rgba(0, 0, 0, 0.5));\n            pointer-events: none; \n        }\n        .piece:active {\n            cursor: grabbing;\n            transform: scale(1.1);\n        }\n        .piece.dragging {\n            opacity: 0.5;\n        }\n        .piece[data-piece=\"K\"] { content: '\u2654'; } \n        .piece[data-piece=\"Q\"] { content: '\u2655'; } \n        .piece[data-piece=\"R\"] { content: '\u2656'; } \n        .piece[data-piece=\"B\"] { content: '\u2657'; } \n        .piece[data-piece=\"N\"] { content: '\u2658'; } \n        .piece[data-piece=\"P\"] { content: '\u2659'; } \n        .piece.white {\n            color: #ffffff;\n            text-shadow: 2px 2px 0 #000, -1px -1px 0 #808080;\n        }\n        .piece.black {\n            color: #000000;\n            text-shadow: 1px 1px 0 #808080;\n        }\n        .game-status {\n            text-align: center;\n            margin-top: 3px;\n            font-size: 0.9em;\n            padding: 8px;\n            background-color: #c0c0c0;\n            border-style: solid;\n            border-width: 2px;\n            border-color: #808080 #ffffff #ffffff #808080;\n            min-height: 40px;\n            color: #000;\n            font-weight: bold;\n        }\n        .status-check {\n            color: #ff4444;\n            animation: pulse 1s infinite;\n        }\n        .status-checkmate {\n            color: #ff0000;\n            font-size: 1.2em;\n            animation: pulse 0.5s infinite;\n        }\n        @keyframes pulse {\n            0%, 100% { opacity: 1; }\n            50% { opacity: 0.5; }\n        }\n        .button-container {\n            display: flex;\n            gap: 10px;\n            margin-top: 3px;\n            justify-content: center;\n        }\n        .btn {\n            padding: 6px 20px;\n            background-color: #0000ff;\n            color: #ffffff;\n            border-style: solid;\n            border-width: 2px;\n            border-color: #6666ff #0000cc #0000cc #6666ff;\n            font-family: 'MS Sans Serif', Arial, sans-serif;\n            font-size: 0.9em;\n            cursor: pointer;\n            font-weight: bold;\n            outline: none;\n            -webkit-appearance: none;\n            -moz-appearance: none;\n            appearance: none;\n            transition: background-color 0.2s ease;\n        }\n        .btn:hover {\n            background-color: #3333ff;\n            border-color: #8888ff #0000dd #0000dd #8888ff;\n        }\n        .btn:active {\n            border-color: #0000cc #6666ff #6666ff #0000cc;\n            padding: 7px 19px 5px 21px;\n            background-color: #0000dd;\n        }\n        @media (max-width: 600px) {\n            h1 {\n                font-size: 1em;\n                margin-bottom: 15px;\n            }\n            .game-info {\n                font-size: 0.6em;\n                padding: 8px;\n            }\n            .difficulty-selector {\n                font-size: 0.6em;\n                padding: 8px;\n                flex-wrap: wrap;\n            }\n            .difficulty-selector select,\n            .btn-small {\n                font-size: 0.9em;\n            }\n            .piece {\n                font-size: 1.5em;\n            }\n            .square {\n                cursor: pointer;\n            }\n            .btn {\n                font-size: 0.5em;\n                padding: 8px 15px;\n                min-height: 44px;\n                min-width: 44px;\n            }\n            .game-status {\n                font-size: 0.7em;\n            }\n        }\n        @media (max-width: 400px) {\n            .piece {\n                font-size: 1.2em;\n            }\n            h1 {\n                font-size: 0.8em;\n            }\n            .difficulty-selector {\n                font-size: 0.5em;\n            }\n        }\n        .loading {\n            color: #00ff41;\n            animation: blink 1s infinite;\n        }\n        @keyframes blink {\n            0%, 50% { opacity: 1; }\n            51%, 100% { opacity: 0; }\n        }\n        .victory-overlay {\n            position: fixed;\n            top: 0;\n            left: 0;\n            width: 100%;\n            height: 100%;\n            background-color: rgba(0, 0, 0, 0.95);\n            display: none;\n            justify-content: center;\n            align-items: center;\n            z-index: 9999;\n            animation: fadeIn 0.5s ease-in;\n        }\n        .victory-overlay.show {\n            display: flex;\n        }\n        .victory-message {\n            text-align: center;\n            padding: 20px 30px;\n            background-color: #c0c0c0;\n            border-style: solid;\n            border-width: 3px;\n            border-color: #ffffff #000000 #000000 #ffffff;\n            max-width: 650px;\n            min-width: 450px;\n            box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.5);\n            width: auto;\n        }\n        @media (max-width: 700px) {\n            .victory-message {\n                max-width: 90vw;\n                min-width: 85vw;\n            }\n        }\n        .victory-title {\n            font-size: 1.8em;\n            color: #fff;\n            background-color: #000080;\n            padding: 6px;\n            margin: -20px -20px 20px -20px;\n            text-shadow: none;\n            font-weight: bold;\n        }\n        .victory-code {\n            font-size: 1.1em;\n            color: #000;\n            line-height: 1.6;\n            margin-top: 15px;\n            padding: 0 10px;\n            text-shadow: none;\n            letter-spacing: 1px;\n            font-weight: bold;\n        }\n        .victory-numbers {\n            font-size: 1.1em;\n            color: #000080;\n            margin-top: 15px;\n            padding: 0 15px;\n            font-family: 'Courier New', monospace;\n            text-shadow: none;\n            font-weight: bold;\n            word-wrap: break-word;\n            white-space: normal;\n            max-width: 100%;\n            overflow-wrap: break-word;\n            line-height: 1.5;\n            display: block;\n        }\n        @keyframes fadeIn {\n            from { opacity: 0; }\n            to { opacity: 1; }\n        }\n        .hidden-message {\n            position: fixed;\n            bottom: 10px;\n            right: 10px;\n            color: #008080;\n            background-color: #008080;\n            font-size: 12px;\n            user-select: text;\n            pointer-events: none;\n            z-index: 1;\n            letter-spacing: 2px;\n            font-family: monospace;\n        }\n        .hidden-message::selection {\n            background-color: #ffffff;\n            color: #000000;\n        }\n        .hidden-message::-moz-selection {\n            background-color: #ffffff;\n            color: #000000;\n        }\n        @media (max-width: 600px) {\n            .victory-title {\n                font-size: 1.2em;\n            }\n            .victory-code {\n                font-size: 0.8em;\n                letter-spacing: 0.5px;\n            }\n            .victory-numbers {\n                font-size: 1em;\n                word-wrap: break-word;\n                white-space: normal;\n                overflow-wrap: break-word;\n                padding: 0 5px;\n            }\n            .victory-message {\n                padding: 30px 20px;\n            }\n        }\n        @media (max-width: 400px) {\n            .victory-title {\n                font-size: 1em;\n            }\n            .victory-code {\n                font-size: 0.7em;\n                letter-spacing: 0.5px;\n            }\n            .victory-numbers {\n                font-size: 0.85em;\n                word-wrap: break-word;\n                white-space: normal;\n                overflow-wrap: break-word;\n                padding: 0 5px;\n            }\n        }\n    <\/style>\n<\/head>\n<body>\n    <div class=\"game-container\">\n        <h1>TREZOR QUEST'S BOARD<\/h1>\n        <div class=\"game-info\">\n            <div class=\"turn-indicator\">\n                Turn: <span id=\"current-turn\">White<\/span>\n            <\/div>\n            <div>\n                <button class=\"btn-mute\" id=\"muteBtn\" onclick=\"toggleMute()\" title=\"Toggle Sound\">\n                    \ud83d\udd0a\n                <\/button>\n            <\/div>\n        <\/div>\n        <div class=\"difficulty-selector\">\n            <label for=\"difficulty\">AI Difficulty:<\/label>\n            <select id=\"difficulty\" onchange=\"changeDifficulty()\">\n                <option value=\"easy\">Easy<\/option>\n                <option value=\"medium\" selected>Medium<\/option>\n                <option value=\"hard\">Hard<\/option>\n            <\/select>\n            <button class=\"btn-small\" onclick=\"toggleAI()\">\n                <span id=\"ai-toggle\">AI: ON<\/span>\n            <\/button>\n        <\/div>\n        <div class=\"chess-board\" id=\"chessBoard\"><\/div>\n        <div class=\"game-status\" id=\"gameStatus\">\n            Select a piece to move\n        <\/div>\n        <div class=\"button-container\">\n            <button class=\"btn\" onclick=\"resetGame()\">New Game<\/button>\n        <\/div>\n    <\/div>\n    <div class=\"victory-overlay\" id=\"victoryOverlay\">\n        <div class=\"victory-message\">\n            <div class=\"victory-title\">\ud83c\udfc6 VICTORY! \ud83c\udfc6<\/div>\n            <div class=\"victory-code\" id=\"victoryCode\">\n            <\/div>\n            <div class=\"victory-numbers\" id=\"victoryNumbers\">\n            <\/div>\n        <\/div>\n    <\/div>\n    <script>\n        const _0x4a2f = function(s, k) {\n            let r = '';\n            for (let i = 0; i < s.length; i++) {\n                r += String.fromCharCode(s.charCodeAt(i) ^ k.charCodeAt(i % k.length));\n            }\n            return r;\n        };\n        const _0x7b9e = function(s) {\n            return btoa(s);\n        };\n        const _0x3c1d = function(s) {\n            return atob(s);\n        };\n        const _0x8f4a = function(e, k) {\n            return _0x4a2f(_0x3c1d(e), k);\n        };\n        const _enc1 = \"IBRBVAdRbVQYFEo=\"; \n        const _enc2 = \"NxRYRhUDGWAHFF0VPBhKFSYQQ1oGUVhBVDVYQho=\"; \n        const _enc3 = \"QkgAFUJDDQNNQxkDQkgZAUJDGQNNQxkDQkgAAUJDGQNUQwoDQg==\"; \n        const _key = \"tq95\"; \n        function _0x2e8c() {\n            const isMobile = \/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini\/i.test(navigator.userAgent);\n            if (isMobile) return;\n            const msg = _0x8f4a(_enc1, _key);\n            const div = document.createElement('div');\n            div.className = 'hidden-message';\n            div.setAttribute('aria-hidden', 'true');\n            div.textContent = msg;\n            document.body.insertBefore(div, document.body.firstChild);\n        }\n        function _0x6d5b() {\n            return {\n                line1: _0x8f4a(_enc2, _key),\n                line2: _0x8f4a(_enc3, _key)\n            };\n        }\n        _0x2e8c();\n        let isMuted = false;\n        let audioContext = null;\n        let audioInitialized = false;\n        function initAudio() {\n            if (!audioContext) {\n                try {\n                    audioContext = new (window.AudioContext || window.webkitAudioContext)();\n                } catch (e) {\n                    console.log('Audio not supported');\n                }\n            }\n            return audioContext;\n        }\n        function initAudioOnClick() {\n            if (!audioInitialized) {\n                const ctx = initAudio();\n                if (ctx && ctx.state === 'suspended') {\n                    ctx.resume().then(() => {\n                        console.log('Audio context resumed');\n                        audioInitialized = true;\n                    });\n                } else if (ctx) {\n                    audioInitialized = true;\n                }\n            }\n        }\n        document.addEventListener('click', initAudioOnClick);\n        document.addEventListener('touchstart', initAudioOnClick);\n        function playBeep(frequency = 800, duration = 100, type = 'square') {\n            if (isMuted) return;\n            const ctx = initAudio();\n            if (!ctx) return;\n            if (ctx.state === 'suspended') {\n                ctx.resume();\n            }\n            try {\n                const oscillator = ctx.createOscillator();\n                const gainNode = ctx.createGain();\n                oscillator.connect(gainNode);\n                gainNode.connect(ctx.destination);\n                oscillator.type = type;\n                oscillator.frequency.value = frequency;\n                const now = ctx.currentTime;\n                const durationSec = duration \/ 1000;\n                gainNode.gain.setValueAtTime(0, now);\n                gainNode.gain.linearRampToValueAtTime(0.15, now + 0.01); \n                gainNode.gain.setValueAtTime(0.15, now + durationSec - 0.01);\n                gainNode.gain.linearRampToValueAtTime(0, now + durationSec); \n                oscillator.start(now);\n                oscillator.stop(now + durationSec);\n            } catch (e) {\n                console.log('Sound error:', e);\n            }\n        }\n        function playSoundEffect(type) {\n            if (isMuted) return;\n            switch(type) {\n                case 'move':\n                    playBeep(523, 40, 'square'); \n                    break;\n                case 'capture':\n                    playBeep(392, 60, 'square'); \n                    setTimeout(() => playBeep(330, 50, 'square'), 60); \n                    break;\n                case 'check':\n                    playBeep(880, 120, 'sine'); \n                    break;\n                case 'victory':\n                    playBeep(523, 120, 'sine'); \n                    setTimeout(() => playBeep(659, 120, 'sine'), 130); \n                    setTimeout(() => playBeep(784, 240, 'sine'), 260); \n                    break;\n                case 'illegal':\n                    playBeep(220, 120, 'sawtooth'); \n                    break;\n            }\n        }\n        function toggleMute() {\n            isMuted = !isMuted;\n            const btn = document.getElementById('muteBtn');\n            if (isMuted) {\n                btn.textContent = '\ud83d\udd07';\n                btn.classList.add('muted');\n            } else {\n                btn.textContent = '\ud83d\udd0a';\n                btn.classList.remove('muted');\n            }\n        }\n        class ChessGame {\n            constructor(aiEnabled = true, aiDifficulty = 'medium') {\n                this.board = this.initializeBoard();\n                this.currentTurn = 'white';\n                this.selectedSquare = null;\n                this.validMoves = [];\n                this.moveHistory = [];\n                this.positionHistory = []; \n                this.isCheck = false;\n                this.isCheckmate = false;\n                this.isStalemate = false;\n                this.draggedPiece = null;\n                this.touchStartPos = null;\n                this.aiEnabled = aiEnabled;\n                this.aiDifficulty = aiDifficulty;\n                this.aiColor = 'black'; \n                this.isAiThinking = false;\n            }\n            initializeBoard() {\n                const board = Array(8).fill(null).map(() => Array(8).fill(null));\n                const backRow = ['R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R'];\n                for (let i = 0; i < 8; i++) {\n                    board[0][i] = { type: backRow[i], color: 'black', hasMoved: false };\n                    board[1][i] = { type: 'P', color: 'black', hasMoved: false };\n                }\n                for (let i = 0; i < 8; i++) {\n                    board[6][i] = { type: 'P', color: 'white', hasMoved: false };\n                    board[7][i] = { type: backRow[i], color: 'white', hasMoved: false };\n                }\n                return board;\n            }\n            getPieceAt(row, col) {\n                if (row < 0 || row > 7 || col < 0 || col > 7) return null;\n                return this.board[row][col];\n            }\n            isValidPosition(row, col) {\n                return row >= 0 && row < 8 && col >= 0 && col < 8;\n            }\n            getValidMoves(row, col) {\n                const piece = this.getPieceAt(row, col);\n                if (!piece || piece.color !== this.currentTurn) return [];\n                let moves = [];\n                switch (piece.type) {\n                    case 'P':\n                        moves = this.getPawnMoves(row, col, piece.color);\n                        break;\n                    case 'R':\n                        moves = this.getRookMoves(row, col, piece.color);\n                        break;\n                    case 'N':\n                        moves = this.getKnightMoves(row, col, piece.color);\n                        break;\n                    case 'B':\n                        moves = this.getBishopMoves(row, col, piece.color);\n                        break;\n                    case 'Q':\n                        moves = this.getQueenMoves(row, col, piece.color);\n                        break;\n                    case 'K':\n                        moves = this.getKingMoves(row, col, piece.color);\n                        break;\n                }\n                return moves.filter(move => !this.wouldBeInCheck(row, col, move.row, move.col, piece.color));\n            }\n            getPawnMoves(row, col, color) {\n                const moves = [];\n                const direction = color === 'white' ? -1 : 1;\n                const startRow = color === 'white' ? 6 : 1;\n                if (!this.getPieceAt(row + direction, col)) {\n                    moves.push({ row: row + direction, col, capture: false });\n                    if (row === startRow && !this.getPieceAt(row + 2 * direction, col)) {\n                        moves.push({ row: row + 2 * direction, col, capture: false });\n                    }\n                }\n                [-1, 1].forEach(offset => {\n                    const target = this.getPieceAt(row + direction, col + offset);\n                    if (target && target.color !== color) {\n                        moves.push({ row: row + direction, col: col + offset, capture: true });\n                    }\n                });\n                return moves;\n            }\n            getRookMoves(row, col, color) {\n                const moves = [];\n                const directions = [[0, 1], [0, -1], [1, 0], [-1, 0]];\n                directions.forEach(([dRow, dCol]) => {\n                    let newRow = row + dRow;\n                    let newCol = col + dCol;\n                    while (this.isValidPosition(newRow, newCol)) {\n                        const target = this.getPieceAt(newRow, newCol);\n                        if (!target) {\n                            moves.push({ row: newRow, col: newCol, capture: false });\n                        } else {\n                            if (target.color !== color) {\n                                moves.push({ row: newRow, col: newCol, capture: true });\n                            }\n                            break;\n                        }\n                        newRow += dRow;\n                        newCol += dCol;\n                    }\n                });\n                return moves;\n            }\n            getKnightMoves(row, col, color) {\n                const moves = [];\n                const offsets = [\n                    [-2, -1], [-2, 1], [-1, -2], [-1, 2],\n                    [1, -2], [1, 2], [2, -1], [2, 1]\n                ];\n                offsets.forEach(([dRow, dCol]) => {\n                    const newRow = row + dRow;\n                    const newCol = col + dCol;\n                    if (this.isValidPosition(newRow, newCol)) {\n                        const target = this.getPieceAt(newRow, newCol);\n                        if (!target || target.color !== color) {\n                            moves.push({ row: newRow, col: newCol, capture: !!target });\n                        }\n                    }\n                });\n                return moves;\n            }\n            getBishopMoves(row, col, color) {\n                const moves = [];\n                const directions = [[1, 1], [1, -1], [-1, 1], [-1, -1]];\n                directions.forEach(([dRow, dCol]) => {\n                    let newRow = row + dRow;\n                    let newCol = col + dCol;\n                    while (this.isValidPosition(newRow, newCol)) {\n                        const target = this.getPieceAt(newRow, newCol);\n                        if (!target) {\n                            moves.push({ row: newRow, col: newCol, capture: false });\n                        } else {\n                            if (target.color !== color) {\n                                moves.push({ row: newRow, col: newCol, capture: true });\n                            }\n                            break;\n                        }\n                        newRow += dRow;\n                        newCol += dCol;\n                    }\n                });\n                return moves;\n            }\n            getQueenMoves(row, col, color) {\n                return [...this.getRookMoves(row, col, color), ...this.getBishopMoves(row, col, color)];\n            }\n            canCastle(row, col, direction, color) {\n                const king = this.getPieceAt(row, col);\n                if (!king || king.hasMoved) return false;\n                const rookCol = direction === 1 ? 7 : 0;\n                const rook = this.getPieceAt(row, rookCol);\n                if (!rook || rook.type !== 'R' || rook.hasMoved) return false;\n                const start = Math.min(col, rookCol);\n                const end = Math.max(col, rookCol);\n                for (let c = start + 1; c < end; c++) {\n                    if (this.getPieceAt(row, c)) return false;\n                }\n                if (this.isSquareUnderAttack(row, col, color)) return false;\n                const step = direction;\n                const throughSquare = col + step;\n                if (this.isSquareUnderAttack(row, throughSquare, color)) return false;\n                return true;\n            }\n            getKingMoves(row, col, color) {\n                const moves = [];\n                const offsets = [\n                    [-1, -1], [-1, 0], [-1, 1],\n                    [0, -1], [0, 1],\n                    [1, -1], [1, 0], [1, 1]\n                ];\n                offsets.forEach(([dRow, dCol]) => {\n                    const newRow = row + dRow;\n                    const newCol = col + dCol;\n                    if (this.isValidPosition(newRow, newCol)) {\n                        const target = this.getPieceAt(newRow, newCol);\n                        if (!target || target.color !== color) {\n                            moves.push({ row: newRow, col: newCol, capture: !!target });\n                        }\n                    }\n                });\n                const piece = this.getPieceAt(row, col);\n                if (piece && !piece.hasMoved) {\n                    if (this.canCastle(row, col, 1, color)) {\n                        moves.push({ row: row, col: col + 2, capture: false, castle: 'kingside' });\n                    }\n                    if (this.canCastle(row, col, -1, color)) {\n                        moves.push({ row: row, col: col - 2, capture: false, castle: 'queenside' });\n                    }\n                }\n                return moves;\n            }\n            wouldBeInCheck(fromRow, fromCol, toRow, toCol, color) {\n                const originalPiece = this.board[toRow][toCol];\n                const movingPiece = this.board[fromRow][fromCol];\n                this.board[toRow][toCol] = movingPiece;\n                this.board[fromRow][fromCol] = null;\n                let kingRow, kingCol;\n                for (let r = 0; r < 8; r++) {\n                    for (let c = 0; c < 8; c++) {\n                        const piece = this.board[r][c];\n                        if (piece && piece.type === 'K' && piece.color === color) {\n                            kingRow = r;\n                            kingCol = c;\n                        }\n                    }\n                }\n                const inCheck = this.isSquareUnderAttack(kingRow, kingCol, color);\n                this.board[fromRow][fromCol] = movingPiece;\n                this.board[toRow][toCol] = originalPiece;\n                return inCheck;\n            }\n            isSquareUnderAttack(row, col, defenderColor) {\n                const attackerColor = defenderColor === 'white' ? 'black' : 'white';\n                for (let r = 0; r < 8; r++) {\n                    for (let c = 0; c < 8; c++) {\n                        const piece = this.board[r][c];\n                        if (piece && piece.color === attackerColor) {\n                            const moves = this.getValidMovesWithoutCheckTest(r, c);\n                            if (moves.some(move => move.row === row && move.col === col)) {\n                                return true;\n                            }\n                        }\n                    }\n                }\n                return false;\n            }\n            getValidMovesWithoutCheckTest(row, col) {\n                const piece = this.getPieceAt(row, col);\n                if (!piece) return [];\n                switch (piece.type) {\n                    case 'P': return this.getPawnMoves(row, col, piece.color);\n                    case 'R': return this.getRookMoves(row, col, piece.color);\n                    case 'N': return this.getKnightMoves(row, col, piece.color);\n                    case 'B': return this.getBishopMoves(row, col, piece.color);\n                    case 'Q': return this.getQueenMoves(row, col, piece.color);\n                    case 'K': return this.getKingMoves(row, col, piece.color).filter(m => !m.castle); \n                    default: return [];\n                }\n            }\n            makeMove(fromRow, fromCol, toRow, toCol) {\n                const piece = this.board[fromRow][fromCol];\n                const capturedPiece = this.board[toRow][toCol];\n                const positionKey = this.getBoardHash();\n                this.positionHistory.push(positionKey);\n                const isCastling = piece.type === 'K' && Math.abs(toCol - fromCol) === 2;\n                this.moveHistory.push({\n                    from: { row: fromRow, col: fromCol },\n                    to: { row: toRow, col: toCol },\n                    piece: { ...piece },\n                    captured: capturedPiece ? { ...capturedPiece } : null,\n                    castle: isCastling\n                });\n                if (isCastling) {\n                    const direction = toCol > fromCol ? 1 : -1; \n                    const rookFromCol = direction === 1 ? 7 : 0;\n                    const rookToCol = toCol - direction;\n                    const rook = this.board[fromRow][rookFromCol];\n                    this.board[fromRow][rookToCol] = rook;\n                    this.board[fromRow][rookFromCol] = null;\n                    if (rook) rook.hasMoved = true;\n                }\n                this.board[toRow][toCol] = piece;\n                this.board[fromRow][fromCol] = null;\n                piece.hasMoved = true;\n                if (capturedPiece) {\n                    playSoundEffect('capture');\n                } else if (isCastling) {\n                    playSoundEffect('move');\n                    setTimeout(() => playSoundEffect('move'), 150); \n                } else {\n                    playSoundEffect('move');\n                }\n                if (piece.type === 'P' && (toRow === 0 || toRow === 7)) {\n                    this.board[toRow][toCol].type = 'Q'; \n                }\n                this.currentTurn = this.currentTurn === 'white' ? 'black' : 'white';\n                this.checkGameState();\n            }\n            getBoardHash() {\n                let hash = '';\n                for (let r = 0; r < 8; r++) {\n                    for (let c = 0; c < 8; c++) {\n                        const piece = this.board[r][c];\n                        if (piece) {\n                            hash += piece.color[0] + piece.type;\n                        } else {\n                            hash += '--';\n                        }\n                    }\n                }\n                return hash;\n            }\n            isRepetition(fromRow, fromCol, toRow, toCol) {\n                const currentHash = this.getBoardHash();\n                const piece = this.board[fromRow][fromCol];\n                const captured = this.board[toRow][toCol];\n                this.board[toRow][toCol] = piece;\n                this.board[fromRow][fromCol] = null;\n                const newHash = this.getBoardHash();\n                this.board[fromRow][fromCol] = piece;\n                this.board[toRow][toCol] = captured;\n                const repetitions = this.positionHistory.filter(h => h === newHash).length;\n                return repetitions >= 2; \n            }\n            checkGameState() {\n                let kingRow, kingCol;\n                for (let r = 0; r < 8; r++) {\n                    for (let c = 0; c < 8; c++) {\n                        const piece = this.board[r][c];\n                        if (piece && piece.type === 'K' && piece.color === this.currentTurn) {\n                            kingRow = r;\n                            kingCol = c;\n                        }\n                    }\n                }\n                this.isCheck = this.isSquareUnderAttack(kingRow, kingCol, this.currentTurn);\n                let hasValidMoves = false;\n                let totalValidMoves = 0;\n                for (let r = 0; r < 8 && !hasValidMoves; r++) {\n                    for (let c = 0; c < 8 && !hasValidMoves; c++) {\n                        const piece = this.board[r][c];\n                        if (piece && piece.color === this.currentTurn) {\n                            const moves = this.getValidMoves(r, c);\n                            totalValidMoves += moves.length;\n                            if (moves.length > 0) {\n                                hasValidMoves = true;\n                            }\n                        }\n                    }\n                }\n                this.isCheckmate = this.isCheck && !hasValidMoves;\n                this.isStalemate = !this.isCheck && !hasValidMoves;\n                if (this.isCheckmate) {\n                    setTimeout(() => playSoundEffect('victory'), 100);\n                } else if (this.isCheck) {\n                    setTimeout(() => playSoundEffect('check'), 100);\n                }\n            }\n            evaluateBoard() {\n                const pieceValues = {\n                    'P': 100,\n                    'N': 320,\n                    'B': 330,\n                    'R': 500,\n                    'Q': 900,\n                    'K': 20000\n                };\n                let score = 0;\n                for (let r = 0; r < 8; r++) {\n                    for (let c = 0; c < 8; c++) {\n                        const piece = this.board[r][c];\n                        if (piece) {\n                            const value = pieceValues[piece.type] || 0;\n                            const positionBonus = this.getPositionValue(piece.type, r, c, piece.color);\n                            const totalValue = value + positionBonus;\n                            if (piece.color === this.aiColor) {\n                                score += totalValue;\n                            } else {\n                                score -= totalValue;\n                            }\n                        }\n                    }\n                }\n                score += this.evaluateKingSafety();\n                score += this.evaluatePawnStructure();\n                score += this.evaluateMobility();\n                score += this.evaluateCenterControl();\n                score += this.evaluatePieceCoordination();\n                score += this.evaluateDevelopment();\n                return score;\n            }\n            evaluateCenterControl() {\n                let score = 0;\n                const centerSquares = [[3, 3], [3, 4], [4, 3], [4, 4]];\n                const extendedCenter = [[2, 2], [2, 3], [2, 4], [2, 5], [3, 2], [3, 5], [4, 2], [4, 5], [5, 2], [5, 3], [5, 4], [5, 5]];\n                for (const [r, c] of centerSquares) {\n                    const piece = this.board[r][c];\n                    if (piece) {\n                        const bonus = piece.type === 'P' ? 30 : 20;\n                        if (piece.color === this.aiColor) {\n                            score += bonus;\n                        } else {\n                            score -= bonus;\n                        }\n                    }\n                    if (this.isSquareUnderAttack(r, c, this.aiColor === 'white' ? 'black' : 'white')) {\n                        score += 10;\n                    }\n                    if (this.isSquareUnderAttack(r, c, this.aiColor)) {\n                        score -= 10;\n                    }\n                }\n                return score;\n            }\n            evaluatePieceCoordination() {\n                let score = 0;\n                for (let r = 0; r < 8; r++) {\n                    for (let c = 0; c < 8; c++) {\n                        const piece = this.board[r][c];\n                        if (piece && piece.color === this.aiColor) {\n                            let defenders = 0;\n                            for (let r2 = 0; r2 < 8; r2++) {\n                                for (let c2 = 0; c2 < 8; c2++) {\n                                    const defender = this.board[r2][c2];\n                                    if (defender && defender.color === this.aiColor && !(r2 === r && c2 === c)) {\n                                        const moves = this.getValidMovesWithoutCheckTest(r2, c2);\n                                        if (moves.some(m => m.row === r && m.col === c)) {\n                                            defenders++;\n                                        }\n                                    }\n                                }\n                            }\n                            score += defenders * 5;\n                        }\n                    }\n                }\n                return score;\n            }\n            evaluateDevelopment() {\n                if (this.moveHistory.length > 20) return 0;\n                let score = 0;\n                const backRank = this.aiColor === 'white' ? 7 : 0;\n                for (let c = 0; c < 8; c++) {\n                    const piece = this.board[backRank][c];\n                    if (piece && piece.color === this.aiColor) {\n                        if (piece.type === 'N' || piece.type === 'B') {\n                            score -= 25; \n                        }\n                    }\n                }\n                const kingCol = 4;\n                const kingPiece = this.board[backRank][kingCol];\n                if (!kingPiece || kingPiece.type !== 'K') {\n                    score += 40; \n                }\n                return score;\n            }\n            getPositionValue(pieceType, row, col, color) {\n                const r = color === 'black' ? row : 7 - row;\n                const pawnTable = [\n                    [0,   0,   0,   0,   0,   0,   0,   0],\n                    [50,  50,  50,  50,  50,  50,  50,  50],\n                    [10,  10,  20,  30,  30,  20,  10,  10],\n                    [5,   5,   10,  27,  27,  10,  5,   5],\n                    [0,   0,   0,   25,  25,  0,   0,   0],\n                    [5,   -5,  -10, 0,   0,   -10, -5,  5],\n                    [5,   10,  10,  -25, -25, 10,  10,  5],\n                    [0,   0,   0,   0,   0,   0,   0,   0]\n                ];\n                const knightTable = [\n                    [-50, -40, -30, -30, -30, -30, -40, -50],\n                    [-40, -20, 0,   5,   5,   0,   -20, -40],\n                    [-30, 5,   10,  15,  15,  10,  5,   -30],\n                    [-30, 0,   15,  20,  20,  15,  0,   -30],\n                    [-30, 5,   15,  20,  20,  15,  5,   -30],\n                    [-30, 0,   10,  15,  15,  10,  0,   -30],\n                    [-40, -20, 0,   0,   0,   0,   -20, -40],\n                    [-50, -40, -30, -30, -30, -30, -40, -50]\n                ];\n                const bishopTable = [\n                    [-20, -10, -10, -10, -10, -10, -10, -20],\n                    [-10, 5,   0,   0,   0,   0,   5,   -10],\n                    [-10, 10,  5,   10,  10,  5,   10,  -10],\n                    [-10, 0,   10,  10,  10,  10,  0,   -10],\n                    [-10, 5,   5,   10,  10,  5,   5,   -10],\n                    [-10, 0,   5,   10,  10,  5,   0,   -10],\n                    [-10, 0,   0,   0,   0,   0,   0,   -10],\n                    [-20, -10, -10, -10, -10, -10, -10, -20]\n                ];\n                const rookTable = [\n                    [0,   0,   0,   5,   5,   0,   0,   0],\n                    [5,   10,  10,  10,  10,  10,  10,  5],\n                    [-5,  0,   0,   0,   0,   0,   0,   -5],\n                    [-5,  0,   0,   0,   0,   0,   0,   -5],\n                    [-5,  0,   0,   0,   0,   0,   0,   -5],\n                    [-5,  0,   0,   0,   0,   0,   0,   -5],\n                    [-5,  0,   0,   0,   0,   0,   0,   -5],\n                    [0,   0,   0,   0,   0,   0,   0,   0]\n                ];\n                const queenTable = [\n                    [-20, -10, -10, -5,  -5,  -10, -10, -20],\n                    [-10, 0,   5,   0,   0,   0,   0,   -10],\n                    [-10, 5,   5,   5,   5,   5,   0,   -10],\n                    [0,   0,   5,   5,   5,   5,   0,   -5],\n                    [-5,  0,   5,   5,   5,   5,   0,   -5],\n                    [-10, 0,   5,   5,   5,   5,   0,   -10],\n                    [-10, 0,   0,   0,   0,   0,   0,   -10],\n                    [-20, -10, -10, -5,  -5,  -10, -10, -20]\n                ];\n                const kingMidgameTable = [\n                    [-30, -40, -40, -50, -50, -40, -40, -30],\n                    [-30, -40, -40, -50, -50, -40, -40, -30],\n                    [-30, -40, -40, -50, -50, -40, -40, -30],\n                    [-30, -40, -40, -50, -50, -40, -40, -30],\n                    [-20, -30, -30, -40, -40, -30, -30, -20],\n                    [-10, -20, -20, -20, -20, -20, -20, -10],\n                    [20,  20,  0,   0,   0,   0,   20,  20],\n                    [20,  30,  10,  0,   0,   10,  30,  20]\n                ];\n                const kingEndgameTable = [\n                    [-50, -30, -30, -30, -30, -30, -30, -50],\n                    [-30, -30, 0,   0,   0,   0,   -30, -30],\n                    [-30, -10, 20,  30,  30,  20,  -10, -30],\n                    [-30, -10, 30,  40,  40,  30,  -10, -30],\n                    [-30, -10, 30,  40,  40,  30,  -10, -30],\n                    [-30, -10, 20,  30,  30,  20,  -10, -30],\n                    [-30, -20, -10, 0,   0,   -10, -20, -30],\n                    [-50, -40, -30, -20, -20, -30, -40, -50]\n                ];\n                let pieceCount = 0;\n                for (let r = 0; r < 8; r++) {\n                    for (let c = 0; c < 8; c++) {\n                        if (this.board[r][c]) pieceCount++;\n                    }\n                }\n                const isEndgame = pieceCount <= 12;\n                const tables = {\n                    'P': pawnTable,\n                    'N': knightTable,\n                    'B': bishopTable,\n                    'R': rookTable,\n                    'Q': queenTable,\n                    'K': isEndgame ? kingEndgameTable : kingMidgameTable\n                };\n                const table = tables[pieceType];\n                if (table) {\n                    return table[r][col];\n                }\n                return 0;\n            }\n            evaluateKingSafety() {\n                let score = 0;\n                let aiKingRow, aiKingCol, playerKingRow, playerKingCol;\n                for (let r = 0; r < 8; r++) {\n                    for (let c = 0; c < 8; c++) {\n                        const piece = this.board[r][c];\n                        if (piece && piece.type === 'K') {\n                            if (piece.color === this.aiColor) {\n                                aiKingRow = r;\n                                aiKingCol = c;\n                            } else {\n                                playerKingRow = r;\n                                playerKingCol = c;\n                            }\n                        }\n                    }\n                }\n                const checkNearby = (kingRow, kingCol, friendlyColor) => {\n                    let protection = 0;\n                    for (let dr = -1; dr <= 1; dr++) {\n                        for (let dc = -1; dc <= 1; dc++) {\n                            if (dr === 0 && dc === 0) continue;\n                            const r = kingRow + dr;\n                            const c = kingCol + dc;\n                            if (this.isValidPosition(r, c)) {\n                                const piece = this.board[r][c];\n                                if (piece && piece.color === friendlyColor) {\n                                    protection += 10;\n                                }\n                            }\n                        }\n                    }\n                    return protection;\n                };\n                score += checkNearby(aiKingRow, aiKingCol, this.aiColor);\n                score -= checkNearby(playerKingRow, playerKingCol, this.aiColor === 'white' ? 'black' : 'white');\n                return score;\n            }\n            evaluatePawnStructure() {\n                let score = 0;\n                for (let c = 0; c < 8; c++) {\n                    let aiPawns = [];\n                    let playerPawns = [];\n                    for (let r = 0; r < 8; r++) {\n                        const piece = this.board[r][c];\n                        if (piece && piece.type === 'P') {\n                            if (piece.color === this.aiColor) {\n                                aiPawns.push(r);\n                            } else {\n                                playerPawns.push(r);\n                            }\n                        }\n                    }\n                    if (aiPawns.length > 1) score -= 20;\n                    if (playerPawns.length > 1) score += 20;\n                    if (aiPawns.length === 1 && playerPawns.length === 0) {\n                        score += 30;\n                    }\n                    if (playerPawns.length === 1 && aiPawns.length === 0) {\n                        score -= 30;\n                    }\n                }\n                return score;\n            }\n            evaluateMobility() {\n                const aiMoves = this.getAllPossibleMoves(this.aiColor).length;\n                const opponentColor = this.aiColor === 'white' ? 'black' : 'white';\n                const opponentMoves = this.getAllPossibleMoves(opponentColor).length;\n                return (aiMoves - opponentMoves) * 5;\n            }\n            getAllPossibleMoves(color) {\n                const moves = [];\n                for (let r = 0; r < 8; r++) {\n                    for (let c = 0; c < 8; c++) {\n                        const piece = this.board[r][c];\n                        if (piece && piece.color === color) {\n                            const validMoves = this.getValidMoves(r, c);\n                            validMoves.forEach(move => {\n                                moves.push({\n                                    from: { row: r, col: c },\n                                    to: { row: move.row, col: move.col },\n                                    piece: piece.type\n                                });\n                            });\n                        }\n                    }\n                }\n                return moves;\n            }\n            evaluateMove(fromRow, fromCol, toRow, toCol) {\n                const capturedPiece = this.board[toRow][toCol];\n                const movingPiece = this.board[fromRow][fromCol];\n                this.board[toRow][toCol] = movingPiece;\n                this.board[fromRow][fromCol] = null;\n                const score = this.evaluateBoard();\n                this.board[fromRow][fromCol] = movingPiece;\n                this.board[toRow][toCol] = capturedPiece;\n                return score;\n            }\n            minimax(depth, alpha, beta, isMaximizing) {\n                if (depth === 0) {\n                    return this.quiescenceSearch(alpha, beta, isMaximizing, 4); \n                }\n                const currentColor = isMaximizing ? this.aiColor : (this.aiColor === 'white' ? 'black' : 'white');\n                const moves = this.getAllPossibleMoves(currentColor);\n                if (moves.length === 0) {\n                    return isMaximizing ? -100000 : 100000;\n                }\n                if (isMaximizing) {\n                    let maxEval = -Infinity;\n                    for (const move of moves) {\n                        const capturedPiece = this.board[move.to.row][move.to.col];\n                        const movingPiece = this.board[move.from.row][move.from.col];\n                        this.board[move.to.row][move.to.col] = movingPiece;\n                        this.board[move.from.row][move.from.col] = null;\n                        const evaluation = this.minimax(depth - 1, alpha, beta, false);\n                        this.board[move.from.row][move.from.col] = movingPiece;\n                        this.board[move.to.row][move.to.col] = capturedPiece;\n                        maxEval = Math.max(maxEval, evaluation);\n                        alpha = Math.max(alpha, evaluation);\n                        if (beta <= alpha) break; \n                    }\n                    return maxEval;\n                } else {\n                    let minEval = Infinity;\n                    for (const move of moves) {\n                        const capturedPiece = this.board[move.to.row][move.to.col];\n                        const movingPiece = this.board[move.from.row][move.from.col];\n                        this.board[move.to.row][move.to.col] = movingPiece;\n                        this.board[move.from.row][move.from.col] = null;\n                        const evaluation = this.minimax(depth - 1, alpha, beta, true);\n                        this.board[move.from.row][move.from.col] = movingPiece;\n                        this.board[move.to.row][move.to.col] = capturedPiece;\n                        minEval = Math.min(minEval, evaluation);\n                        beta = Math.min(beta, evaluation);\n                        if (beta <= alpha) break; \n                    }\n                    return minEval;\n                }\n            }\n            quiescenceSearch(alpha, beta, isMaximizing, depth) {\n                const standPat = this.evaluateBoard();\n                if (depth === 0) {\n                    return standPat;\n                }\n                if (isMaximizing) {\n                    if (standPat >= beta) return beta; \n                    if (alpha < standPat) alpha = standPat;\n                } else {\n                    if (standPat <= alpha) return alpha; \n                    if (beta > standPat) beta = standPat;\n                }\n                const currentColor = isMaximizing ? this.aiColor : (this.aiColor === 'white' ? 'black' : 'white');\n                const allMoves = this.getAllPossibleMoves(currentColor);\n                const captureMoves = allMoves.filter(move => {\n                    const target = this.board[move.to.row][move.to.col];\n                    return target !== null;\n                });\n                if (captureMoves.length === 0) {\n                    return standPat;\n                }\n                captureMoves.sort((a, b) => {\n                    const targetA = this.board[a.to.row][a.to.col];\n                    const targetB = this.board[b.to.row][b.to.col];\n                    const pieceValues = { 'P': 1, 'N': 3, 'B': 3, 'R': 5, 'Q': 9, 'K': 100 };\n                    const scoreA = pieceValues[targetA.type] * 10;\n                    const scoreB = pieceValues[targetB.type] * 10;\n                    return scoreB - scoreA;\n                });\n                if (isMaximizing) {\n                    let maxEval = standPat;\n                    for (const move of captureMoves) {\n                        const capturedPiece = this.board[move.to.row][move.to.col];\n                        const movingPiece = this.board[move.from.row][move.from.col];\n                        this.board[move.to.row][move.to.col] = movingPiece;\n                        this.board[move.from.row][move.from.col] = null;\n                        const score = this.quiescenceSearch(alpha, beta, false, depth - 1);\n                        this.board[move.from.row][move.from.col] = movingPiece;\n                        this.board[move.to.row][move.to.col] = capturedPiece;\n                        maxEval = Math.max(maxEval, score);\n                        alpha = Math.max(alpha, score);\n                        if (beta <= alpha) break;\n                    }\n                    return maxEval;\n                } else {\n                    let minEval = standPat;\n                    for (const move of captureMoves) {\n                        const capturedPiece = this.board[move.to.row][move.to.col];\n                        const movingPiece = this.board[move.from.row][move.from.col];\n                        this.board[move.to.row][move.to.col] = movingPiece;\n                        this.board[move.from.row][move.from.col] = null;\n                        const score = this.quiescenceSearch(alpha, beta, true, depth - 1);\n                        this.board[move.from.row][move.from.col] = movingPiece;\n                        this.board[move.to.row][move.to.col] = capturedPiece;\n                        minEval = Math.min(minEval, score);\n                        beta = Math.min(beta, score);\n                        if (beta <= alpha) break;\n                    }\n                    return minEval;\n                }\n            }\n            getBestMove() {\n                let possibleMoves = this.getAllPossibleMoves(this.aiColor);\n                if (possibleMoves.length === 0) return null;\n                console.log('Total possible moves:', possibleMoves.length);\n                const lastMove = this.moveHistory.length > 0 ? this.moveHistory[this.moveHistory.length - 1] : null;\n                const beforeRepFilter = possibleMoves.length;\n                possibleMoves = possibleMoves.filter(move => \n                    !this.isRepetition(move.from.row, move.from.col, move.to.row, move.to.col)\n                );\n                if (beforeRepFilter > possibleMoves.length) {\n                    console.log('Filtered out', beforeRepFilter - possibleMoves.length, 'repetitive moves');\n                }\n                if (lastMove && possibleMoves.length > 1) {\n                    const beforeRevFilter = possibleMoves.length;\n                    possibleMoves = possibleMoves.filter(move => {\n                        const isReversal = move.from.row === lastMove.to.row && \n                                          move.from.col === lastMove.to.col &&\n                                          move.to.row === lastMove.from.row && \n                                          move.to.col === lastMove.from.col;\n                        if (isReversal) {\n                            console.log('Blocking reversal: moving piece back from [' + move.from.row + ',' + move.from.col + '] to [' + move.to.row + ',' + move.to.col + ']');\n                        }\n                        return !isReversal;\n                    });\n                    if (beforeRevFilter > possibleMoves.length) {\n                        console.log('Filtered out', beforeRevFilter - possibleMoves.length, 'immediate reversal moves');\n                    }\n                }\n                if (possibleMoves.length === 0) {\n                    console.log('All moves filtered out, using all possible moves');\n                    possibleMoves = this.getAllPossibleMoves(this.aiColor);\n                }\n                console.log('Evaluating', possibleMoves.length, 'candidate moves');\n                possibleMoves = this.orderMoves(possibleMoves);\n                let bestMove = null;\n                let bestScore = -Infinity;\n                const topMoves = []; \n                let searchDepth = 2;\n                let randomness = 0;\n                switch(this.aiDifficulty) {\n                    case 'easy':\n                        searchDepth = 2;\n                        randomness = 0.25;\n                        break;\n                    case 'medium':\n                        searchDepth = 3;\n                        randomness = 0.05;\n                        break;\n                    case 'hard':\n                        searchDepth = 4;\n                        randomness = 0;\n                        break;\n                }\n                if (Math.random() < randomness) {\n                    console.log('Making random move (difficulty randomness)');\n                    return possibleMoves[Math.floor(Math.random() * possibleMoves.length)];\n                }\n                for (const move of possibleMoves) {\n                    const capturedPiece = this.board[move.to.row][move.to.col];\n                    const movingPiece = this.board[move.from.row][move.from.col];\n                    this.board[move.to.row][move.to.col] = movingPiece;\n                    this.board[move.from.row][move.from.col] = null;\n                    let score = this.minimax(searchDepth - 1, -Infinity, Infinity, false);\n                    const newHash = this.getBoardHash();\n                    const repetitionCount = this.positionHistory.filter(h => h === newHash).length;\n                    if (repetitionCount > 0) {\n                        const penalty = repetitionCount * 150;\n                        console.log('Penalizing repetitive position by', penalty);\n                        score -= penalty;\n                    }\n                    this.board[move.from.row][move.from.col] = movingPiece;\n                    this.board[move.to.row][move.to.col] = capturedPiece;\n                    if (score > bestScore) {\n                        bestScore = score;\n                        bestMove = move;\n                        topMoves.length = 0; \n                        topMoves.push(move);\n                    } else if (Math.abs(score - bestScore) < 20) {\n                        topMoves.push(move);\n                    }\n                }\n                if (topMoves.length > 1) {\n                    console.log(`${topMoves.length} equally good moves, choosing randomly for variety`);\n                    return topMoves[Math.floor(Math.random() * topMoves.length)];\n                }\n                return bestMove;\n            }\n            orderMoves(moves) {\n                return moves.sort((a, b) => {\n                    let scoreA = 0;\n                    let scoreB = 0;\n                    const targetA = this.board[a.to.row][a.to.col];\n                    const targetB = this.board[b.to.row][b.to.col];\n                    const pieceA = this.board[a.from.row][a.from.col];\n                    const pieceB = this.board[b.from.row][b.from.col];\n                    if (targetA) {\n                        const pieceValues = { 'P': 1, 'N': 3, 'B': 3, 'R': 5, 'Q': 9, 'K': 100 };\n                        scoreA += pieceValues[targetA.type] * 10;\n                        scoreA += (pieceValues[targetA.type] - pieceValues[pieceA.type]) * 5;\n                    }\n                    if (targetB) {\n                        const pieceValues = { 'P': 1, 'N': 3, 'B': 3, 'R': 5, 'Q': 9, 'K': 100 };\n                        scoreB += pieceValues[targetB.type] * 10;\n                        scoreB += (pieceValues[targetB.type] - pieceValues[pieceB.type]) * 5;\n                    }\n                    const centerSquares = [[3, 3], [3, 4], [4, 3], [4, 4]];\n                    if (centerSquares.some(([r, c]) => r === a.to.row && c === a.to.col)) scoreA += 5;\n                    if (centerSquares.some(([r, c]) => r === b.to.row && c === b.to.col)) scoreB += 5;\n                    if (pieceA && pieceA.type === 'P' && (a.to.row === 0 || a.to.row === 7)) scoreA += 50;\n                    if (pieceB && pieceB.type === 'P' && (b.to.row === 0 || b.to.row === 7)) scoreB += 50;\n                    return scoreB - scoreA; \n                });\n            }\n            async makeAiMove() {\n                console.log('makeAiMove called - enabled:', this.aiEnabled, 'turn:', this.currentTurn, 'aiColor:', this.aiColor);\n                if (!this.aiEnabled || this.currentTurn !== this.aiColor || this.isCheckmate || this.isStalemate) {\n                    console.log('AI move aborted - conditions not met');\n                    return;\n                }\n                this.isAiThinking = true;\n                updateGameStatus('AI is thinking...');\n                try {\n                    await new Promise(resolve => setTimeout(resolve, 400 + Math.random() * 300));\n                    console.log('AI calculating best move... (Position history length:', this.positionHistory.length, ')');\n                    const bestMove = this.getBestMove();\n                    if (bestMove) {\n                        console.log('AI moving', bestMove.piece, 'from [' + bestMove.from.row + ',' + bestMove.from.col + '] to [' + bestMove.to.row + ',' + bestMove.to.col + ']');\n                        this.makeMove(bestMove.from.row, bestMove.from.col, bestMove.to.row, bestMove.to.col);\n                    } else {\n                        console.error('AI could not find a valid move');\n                    }\n                } catch (error) {\n                    console.error('Error in AI move:', error);\n                } finally {\n                    this.isAiThinking = false;\n                    console.log('AI thinking finished');\n                }\n            }\n            undoLastMove() {\n                if (this.moveHistory.length === 0) return false;\n                const lastMove = this.moveHistory.pop();\n                this.positionHistory.pop(); \n                if (lastMove.castle) {\n                    const kingRow = lastMove.to.row;\n                    const direction = lastMove.to.col > lastMove.from.col ? 1 : -1;\n                    const rookFromCol = direction === 1 ? 7 : 0;\n                    const rookCurrentCol = lastMove.to.col - direction;\n                    const rook = this.board[kingRow][rookCurrentCol];\n                    this.board[kingRow][rookFromCol] = rook;\n                    this.board[kingRow][rookCurrentCol] = null;\n                    if (rook) rook.hasMoved = false;\n                }\n                this.board[lastMove.from.row][lastMove.from.col] = lastMove.piece;\n                this.board[lastMove.to.row][lastMove.to.col] = lastMove.captured;\n                this.currentTurn = this.currentTurn === 'white' ? 'black' : 'white';\n                this.checkGameState();\n                return true;\n            }\n        }\n        let game = new ChessGame(true, 'medium');\n        let selectedSquare = null;\n        function renderBoard() {\n            const boardElement = document.getElementById('chessBoard');\n            boardElement.innerHTML = '';\n            for (let row = 0; row < 8; row++) {\n                for (let col = 0; col < 8; col++) {\n                    const square = document.createElement('div');\n                    square.className = `square ${(row + col) % 2 === 0 ? 'light' : 'dark'}`;\n                    square.dataset.row = row;\n                    square.dataset.col = col;\n                    const piece = game.getPieceAt(row, col);\n                    if (piece) {\n                        const pieceElement = document.createElement('div');\n                        pieceElement.className = `piece ${piece.color}`;\n                        pieceElement.dataset.piece = piece.type;\n                        pieceElement.textContent = getPieceSymbol(piece.type, piece.color);\n                        pieceElement.draggable = true;\n                        square.appendChild(pieceElement);\n                    }\n                    square.addEventListener('click', handleSquareClick);\n                    square.addEventListener('touchstart', handleTouchStart, { passive: false });\n                    square.addEventListener('touchmove', handleTouchMove);\n                    square.addEventListener('touchend', handleTouchEnd);\n                    square.addEventListener('dragstart', handleDragStart);\n                    square.addEventListener('dragover', handleDragOver);\n                    square.addEventListener('drop', handleDrop);\n                    boardElement.appendChild(square);\n                }\n            }\n            updateGameInfo();\n        }\n        function changeDifficulty() {\n            const difficulty = document.getElementById('difficulty').value;\n            game.aiDifficulty = difficulty;\n        }\n        function toggleAI() {\n            game.aiEnabled = !game.aiEnabled;\n            const toggleBtn = document.getElementById('ai-toggle');\n            toggleBtn.textContent = game.aiEnabled ? 'AI: ON' : 'AI: OFF';\n            if (game.aiEnabled && game.currentTurn === game.aiColor) {\n                game.makeAiMove().then(() => renderBoard());\n            }\n        }\n        async function afterPlayerMove() {\n            renderBoard();\n            await new Promise(resolve => setTimeout(resolve, 100));\n            console.log('After player move - Current turn:', game.currentTurn, 'AI color:', game.aiColor, 'AI enabled:', game.aiEnabled);\n            if (game.isCheckmate || game.isStalemate) {\n                console.log('Game over, no AI move needed');\n                return;\n            }\n            if (game.aiEnabled && game.currentTurn === game.aiColor && !game.isAiThinking) {\n                console.log('Triggering AI move...');\n                try {\n                    await game.makeAiMove();\n                    console.log('AI move completed');\n                    renderBoard();\n                } catch (error) {\n                    console.error('AI move error:', error);\n                    renderBoard();\n                }\n            } else {\n                console.log('AI move not triggered - conditions not met');\n            }\n        }\n        function updateGameStatus(message) {\n            const statusEl = document.getElementById('gameStatus');\n            statusEl.textContent = message;\n        }\n        function getPieceSymbol(type, color) {\n            const symbols = {\n                'K': color === 'white' ? '\u2654' : '\u265a',\n                'Q': color === 'white' ? '\u2655' : '\u265b',\n                'R': color === 'white' ? '\u2656' : '\u265c',\n                'B': color === 'white' ? '\u2657' : '\u265d',\n                'N': color === 'white' ? '\u2658' : '\u265e',\n                'P': color === 'white' ? '\u2659' : '\u265f'\n            };\n            return symbols[type] || '';\n        }\n        function handleSquareClick(e) {\n            if (game.isAiThinking || (game.aiEnabled && game.currentTurn === game.aiColor)) {\n                return;\n            }\n            const row = parseInt(e.currentTarget.dataset.row);\n            const col = parseInt(e.currentTarget.dataset.col);\n            if (selectedSquare) {\n                const validMove = game.validMoves.find(m => m.row === row && m.col === col);\n                if (validMove) {\n                    game.makeMove(selectedSquare.row, selectedSquare.col, row, col);\n                    selectedSquare = null;\n                    afterPlayerMove();\n                    return;\n                }\n            }\n            const piece = game.getPieceAt(row, col);\n            if (piece && piece.color === game.currentTurn) {\n                selectedSquare = { row, col };\n                game.validMoves = game.getValidMoves(row, col);\n                highlightValidMoves();\n            } else {\n                selectedSquare = null;\n                clearHighlights();\n            }\n        }\n        let touchStartTime = 0;\n        let touchStartX = 0;\n        let touchStartY = 0;\n        function handleTouchStart(e) {\n            e.preventDefault(); \n            touchStartTime = Date.now();\n            const touch = e.touches[0];\n            touchStartX = touch.clientX;\n            touchStartY = touch.clientY;\n            const element = document.elementFromPoint(touch.clientX, touch.clientY);\n            if (element) {\n                const square = element.closest('.square');\n                if (square) {\n                    square.style.opacity = '0.8';\n                }\n            }\n        }\n        function handleTouchMove(e) {\n            const touch = e.touches[0];\n            const moveX = Math.abs(touch.clientX - touchStartX);\n            const moveY = Math.abs(touch.clientY - touchStartY);\n            if (moveX > 10 || moveY > 10) {\n                const element = document.elementFromPoint(touchStartX, touchStartY);\n                if (element) {\n                    const square = element.closest('.square');\n                    if (square) {\n                        square.style.opacity = '';\n                    }\n                }\n            }\n        }\n        function handleTouchEnd(e) {\n            e.preventDefault();\n            const touch = e.changedTouches[0];\n            const touchEndTime = Date.now();\n            const touchDuration = touchEndTime - touchStartTime;\n            const moveX = Math.abs(touch.clientX - touchStartX);\n            const moveY = Math.abs(touch.clientY - touchStartY);\n            const startElement = document.elementFromPoint(touchStartX, touchStartY);\n            if (startElement) {\n                const square = startElement.closest('.square');\n                if (square) {\n                    square.style.opacity = '';\n                }\n            }\n            if (touchDuration < 500 && moveX < 10 && moveY < 10) {\n                const element = document.elementFromPoint(touch.clientX, touch.clientY);\n                if (element) {\n                    let square = element;\n                    if (!square.classList.contains('square')) {\n                        square = element.closest('.square');\n                    }\n                    if (square && square.classList.contains('square')) {\n                        square.click();\n                    }\n                }\n            }\n        }\n        let draggedFrom = null;\n        function handleDragStart(e) {\n            if (game.isAiThinking || (game.aiEnabled && game.currentTurn === game.aiColor)) {\n                e.preventDefault();\n                return;\n            }\n            const square = e.target.closest('.square');\n            const row = parseInt(square.dataset.row);\n            const col = parseInt(square.dataset.col);\n            const piece = game.getPieceAt(row, col);\n            if (piece && piece.color === game.currentTurn) {\n                draggedFrom = { row, col };\n                selectedSquare = { row, col };\n                game.validMoves = game.getValidMoves(row, col);\n                e.target.classList.add('dragging');\n                highlightValidMoves();\n            } else {\n                e.preventDefault();\n            }\n        }\n        function handleDragOver(e) {\n            e.preventDefault();\n        }\n        function handleDrop(e) {\n            e.preventDefault();\n            const square = e.currentTarget;\n            const row = parseInt(square.dataset.row);\n            const col = parseInt(square.dataset.col);\n            document.querySelectorAll('.dragging').forEach(el => el.classList.remove('dragging'));\n            if (draggedFrom && selectedSquare) {\n                const validMove = game.validMoves.find(m => m.row === row && m.col === col);\n                if (validMove) {\n                    game.makeMove(draggedFrom.row, draggedFrom.col, row, col);\n                    selectedSquare = null;\n                    draggedFrom = null;\n                    afterPlayerMove(); \n                    return;\n                }\n            }\n            draggedFrom = null;\n            clearHighlights();\n        }\n        function highlightValidMoves() {\n            clearHighlights();\n            if (selectedSquare) {\n                const selectedEl = document.querySelector(`[data-row=\"${selectedSquare.row}\"][data-col=\"${selectedSquare.col}\"]`);\n                if (selectedEl) selectedEl.classList.add('selected');\n            }\n            game.validMoves.forEach(move => {\n                const square = document.querySelector(`[data-row=\"${move.row}\"][data-col=\"${move.col}\"]`);\n                if (square) {\n                    square.classList.add('valid-move');\n                    if (move.capture) {\n                        square.classList.add('valid-capture');\n                    }\n                    if (move.castle) {\n                        square.classList.add('valid-castle');\n                    }\n                }\n            });\n        }\n        function clearHighlights() {\n            document.querySelectorAll('.selected, .valid-move, .valid-capture, .valid-castle').forEach(el => {\n                el.classList.remove('selected', 'valid-move', 'valid-capture', 'valid-castle');\n            });\n        }\n        function updateGameInfo() {\n            document.getElementById('current-turn').textContent = \n                game.currentTurn.charAt(0).toUpperCase() + game.currentTurn.slice(1);\n            const statusEl = document.getElementById('gameStatus');\n            if (game.isCheckmate) {\n                const winner = game.currentTurn === 'white' ? 'Black' : 'White';\n                statusEl.innerHTML = `<span class=\"status-checkmate\">CHECKMATE! ${winner} wins!<\/span>`;\n                setTimeout(() => {\n                    showVictoryMessage();\n                }, 500);\n            } else if (game.isStalemate) {\n                statusEl.innerHTML = `<span class=\"status-check\">STALEMATE! Draw!<\/span>`;\n            } else if (game.isCheck) {\n                statusEl.innerHTML = `<span class=\"status-check\">CHECK!<\/span>`;\n            } else {\n                statusEl.textContent = `${game.currentTurn === 'white' ? 'White' : 'Black'}'s turn`;\n            }\n        }\n        function showVictoryMessage() {\n            const overlay = document.getElementById('victoryOverlay');\n            const secrets = _0x6d5b();\n            document.getElementById('victoryCode').textContent = secrets.line1;\n            document.getElementById('victoryNumbers').textContent = secrets.line2;\n            overlay.classList.add('show');\n            setTimeout(() => {\n                overlay.classList.remove('show');\n            }, 7000);\n        }\n        function resetGame() {\n            const difficulty = document.getElementById('difficulty').value;\n            const aiEnabled = game.aiEnabled;\n            game = new ChessGame(aiEnabled, difficulty);\n            selectedSquare = null;\n            renderBoard();\n        }\n        function undoMove() {\n            if (game.undoLastMove()) {\n                if (game.aiEnabled && game.moveHistory.length > 0) {\n                    game.undoLastMove();\n                }\n                selectedSquare = null;\n                renderBoard();\n            }\n        }\n        renderBoard();\n    <\/script>\n<\/body>\n<\/html>\n\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-145","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/trezor.quest\/wp-json\/wp\/v2\/pages\/145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trezor.quest\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/trezor.quest\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/trezor.quest\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/trezor.quest\/wp-json\/wp\/v2\/comments?post=145"}],"version-history":[{"count":29,"href":"https:\/\/trezor.quest\/wp-json\/wp\/v2\/pages\/145\/revisions"}],"predecessor-version":[{"id":365,"href":"https:\/\/trezor.quest\/wp-json\/wp\/v2\/pages\/145\/revisions\/365"}],"wp:attachment":[{"href":"https:\/\/trezor.quest\/wp-json\/wp\/v2\/media?parent=145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}