Download play.html from Convergent-ch/Akron-0.1-Random: direct link, hf CLI and curl.
- Browser
- Download file 12.7 kB
-
https://huggingface.co/Convergent-ch/Akron-0.1-Random/resolve/main/play.html
- Command line
-
hf download hf://Convergent-ch/Akron-0.1-Random/play.html
-
curl -L -o play.html https://huggingface.co/Convergent-ch/Akron-0.1-Random/resolve/main/play.html
12.7 kB
| <html lang="de"> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width,initial-scale=1"> | |
| <title>Arkon Engine 0.1</title> | |
| <style> | |
| :root { color-scheme: dark; font: 16px/1.45 system-ui,sans-serif; background:#302e2b; color:#f4f3ef; } | |
| * { box-sizing:border-box; } | |
| main { width:min(930px,100%); margin:auto; padding:28px 16px; } | |
| h1 { margin:0 0 18px; font-size:clamp(1.6rem,5vw,2.6rem); } | |
| .layout { display:grid; grid-template-columns:minmax(0,600px) minmax(180px,1fr); gap:20px; } | |
| #board { display:grid; grid-template-columns:repeat(8,1fr); aspect-ratio:1; border-radius:4px; overflow:hidden; } | |
| .square { position:relative; width:100%; min-width:0; aspect-ratio:1; border:0; padding:0; display:grid; place-items:center; background:#ebecd0; color:#739552; } | |
| .dark { background:#739552; color:#ebecd0; } | |
| .last, .selected { background:#f5f682; } | |
| .dark.last, .dark.selected { background:#b9ca43; } | |
| .piece { width:96%; height:96%; object-fit:contain; pointer-events:none; user-select:none; } | |
| .target:after { content:""; position:absolute; width:28%; aspect-ratio:1; border-radius:50%; background:#0003; pointer-events:none; } | |
| .occupied.target:after { width:100%; background:none; border:6px solid #0003; box-sizing:border-box; } | |
| .check { background:radial-gradient(ellipse,#ef5b4d 5%,#bd362a 48%,#739552 92%); } | |
| small { position:absolute; pointer-events:none; font:bold clamp(9px,1.7vw,14px) system-ui; color:inherit; } | |
| .file { bottom:1px; right:4px; } .rank { top:1px; left:3px; } | |
| aside { background:#262522; padding:16px; border-radius:8px; align-self:start; } | |
| #moves { max-height:280px; overflow:auto; white-space:pre-wrap; color:#ddd9d2; } | |
| #reset, dialog button { background:#81b64c; color:#17220d; border:0; border-radius:6px; padding:8px 14px; font:inherit; font-weight:700; } | |
| #sound, #pause { display:block; width:100%; background:#393632; color:inherit; border:0; border-radius:6px; margin-top:10px; padding:8px; font:inherit; } | |
| #pause[hidden] { display:none; } | |
| #reset { width:100%; } | |
| button { cursor:pointer; } button:focus-visible { outline:3px solid #ffc745; outline-offset:-3px; } | |
| @media(max-width:680px) { .layout { grid-template-columns:1fr; } } | |
| </style> | |
| <main> | |
| <h1 id="engine-name">Arkon Engine 0.1</h1> | |
| <div class="layout"> | |
| <div id="board" aria-label="Schachbrett"></div> | |
| <aside> | |
| <strong id="players">Du spielst Weiß</strong> | |
| <p id="status" role="status">Lädt …</p> | |
| <p id="search" hidden></p> | |
| <button id="reset">Neue Partie</button> | |
| <button id="pause" hidden>Pausieren</button> | |
| <button id="sound" aria-pressed="true">Ton an</button> | |
| <p id="moves" aria-label="Zugliste"></p> | |
| </aside> | |
| </div> | |
| </main> | |
| <dialog id="promotion"><form method="dialog"><p>Figur für die Umwandlung wählen</p> | |
| <button value="q">Dame</button> <button value="r">Turm</button> | |
| <button value="b">Läufer</button> <button value="n">Springer</button> | |
| </form></dialog> | |
| <script> | |
| const board = document.querySelector('#board'); | |
| const statusText = document.querySelector('#status'); | |
| const moveText = document.querySelector('#moves'); | |
| const promotion = document.querySelector('#promotion'); | |
| const reset = document.querySelector('#reset'); | |
| const sound = document.querySelector('#sound'); | |
| const pause = document.querySelector('#pause'); | |
| const matchMode = new URLSearchParams(location.search).get('match'); | |
| const pondering = matchMode === 'ponder'; | |
| const proBlack = matchMode === 'pro-black'; | |
| const proDuel = matchMode === 'pro' || proBlack; | |
| const strong = matchMode === 'max' || pondering; | |
| let ponderGame; | |
| const watching = strong || proDuel || matchMode === '1'; | |
| let whiteName = proDuel ? (proBlack ? 'Arkon 0.1' : 'Arkon 0.1 Pro') : pondering ? 'Stockfish' : 'Arkon'; | |
| let blackName = proDuel ? (proBlack ? 'Arkon 0.1 Pro' : 'Arkon 0.1') : pondering ? 'Arkon' : 'Stockfish'; | |
| const searchInfo = document.querySelector('#search'); | |
| let paused = false, timer; | |
| if (watching) { | |
| document.querySelector('#players').textContent = whiteName + ' (Weiß) gegen ' + blackName + ' (Schwarz)'; | |
| if (strong) { | |
| searchInfo.hidden = false; | |
| searchInfo.textContent = '5 Sekunden pro Zug'; | |
| } | |
| pause.hidden = false; | |
| } | |
| let muted = localStorage.getItem('arkon-muted') === 'true'; | |
| let audio; | |
| let state, selected, busy = false; | |
| function updateSound() { | |
| sound.textContent = muted ? 'Ton aus' : 'Ton an'; | |
| sound.setAttribute('aria-pressed', String(!muted)); | |
| } | |
| sound.onclick = () => { | |
| muted = !muted; | |
| localStorage.setItem('arkon-muted', String(muted)); | |
| updateSound(); | |
| if (!muted) { unlockSound(); playSound('move'); } | |
| }; | |
| function unlockSound() { | |
| if (muted || !window.AudioContext) return; | |
| audio ||= new AudioContext(); | |
| if (audio.state === 'suspended') audio.resume().catch(() => {}); | |
| } | |
| function playSound(kind, delay = 0) { | |
| if (muted || audio?.state !== 'running') return; | |
| const start = audio.currentTime + delay; | |
| const capture = kind === 'capture'; | |
| const duration = capture ? .078 : .047; | |
| const buffer = audio.createBuffer(1, Math.ceil(audio.sampleRate * duration), audio.sampleRate); | |
| const wave = buffer.getChannelData(0); | |
| for (let i = 0; i < wave.length; i++) { | |
| const t = i / audio.sampleRate; | |
| wave[i] = ((Math.random() * 2 - 1) * .24 + Math.sin(2 * Math.PI * (capture ? 225 : 335) * t) * .76) * Math.exp(-t / .012); | |
| } | |
| const hit = audio.createBufferSource(), volume = audio.createGain(); | |
| hit.buffer = buffer; | |
| volume.gain.value = capture ? .32 : .24; | |
| hit.connect(volume).connect(audio.destination); | |
| hit.start(start); | |
| if (!['check', 'end'].includes(kind)) return; | |
| const tone = audio.createOscillator(), fade = audio.createGain(); | |
| tone.frequency.value = kind === 'check' ? 620 : 405; | |
| fade.gain.setValueAtTime(.09, start + .02); | |
| fade.gain.exponentialRampToValueAtTime(.001, start + .20); | |
| tone.connect(fade).connect(audio.destination); | |
| tone.start(start + .02); | |
| tone.stop(start + .21); | |
| } | |
| updateSound(); | |
| async function request(moves, endpoint = '/game') { | |
| const response = await fetch(endpoint, moves ? {method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(moves)} : {}); | |
| const data = await response.json(); | |
| if (!response.ok) throw new Error(data.error || 'Zug fehlgeschlagen.'); | |
| return data; | |
| } | |
| function draw() { | |
| if (state.engine_name) { | |
| document.title = state.engine_name; | |
| document.querySelector('#engine-name').textContent = state.engine_name; | |
| } | |
| board.replaceChildren(); | |
| const last = state.moves.at(-1); | |
| const targets = new Set(watching ? [] : state.legal.filter(move => move.startsWith(selected ?? '!!')).map(move => move.slice(2,4))); | |
| for (let rank=8; rank>=1; rank--) for (let file=0; file<8; file++) { | |
| const square = 'abcdefgh'[file] + rank; | |
| const piece = state.pieces[square]; | |
| const cell = document.createElement('button'); | |
| cell.className = 'square'; | |
| cell.classList.toggle('dark', (rank + file) % 2 === 1); | |
| cell.classList.toggle('selected', square === selected); | |
| cell.classList.toggle('target', targets.has(square)); | |
| cell.classList.toggle('last', square === last?.slice(0,2) || square === last?.slice(2,4)); | |
| cell.classList.toggle('occupied', !!piece); | |
| cell.classList.toggle('check', state.check && piece === (state.moves.length % 2 ? 'k' : 'K')); | |
| if (piece) { | |
| const img = document.createElement('img'); | |
| img.className = 'piece'; | |
| img.alt = ''; | |
| img.draggable = false; | |
| img.src = '/pieces/' + (piece === piece.toUpperCase() ? 'w' : 'b') + piece.toUpperCase() + '.svg'; | |
| cell.append(img); | |
| } | |
| cell.setAttribute('aria-label', square + (piece ? ' ' + piece : '')); | |
| cell.onclick = () => click(square); | |
| if (rank === 1) { | |
| const coord = document.createElement('small'); | |
| coord.className = 'file'; | |
| coord.textContent = square[0]; | |
| cell.append(coord); | |
| } | |
| if (file === 0) { | |
| const coord = document.createElement('small'); | |
| coord.className = 'rank'; | |
| coord.textContent = rank; | |
| cell.append(coord); | |
| } | |
| board.append(cell); | |
| } | |
| moveText.textContent = state.san; | |
| if (watching) { | |
| if (!proDuel && state.engine_name) { | |
| if (pondering) blackName = state.engine_name; | |
| else whiteName = state.engine_name; | |
| document.querySelector('#players').textContent = whiteName + ' (Weiß) gegen ' + blackName + ' (Schwarz)'; | |
| } | |
| if (strong && state.search) { | |
| const {engine, depth, nodes} = state.search; | |
| searchInfo.textContent = engine + ' · Tiefe ' + (depth ?? '–') + ' · ' + (nodes ?? 0).toLocaleString('de-CH') + ' Stellungen'; | |
| if (pondering && engine === 'Stockfish') { | |
| if (state.search.ponder_hit !== undefined) searchInfo.textContent += state.search.ponder_hit ? ' · Vorhersage getroffen' : ' · Vorhersage verfehlt'; | |
| if (state.search.prediction) searchInfo.textContent += ' · Erwartet ' + state.search.prediction; | |
| } | |
| } else if (strong) { | |
| searchInfo.textContent = (state.search_seconds ?? 5) + ' Sekunden pro Zug'; | |
| } | |
| moveText.scrollTop = moveText.scrollHeight; | |
| statusText.textContent = state.result | |
| ? (state.result === '1/2-1/2' ? 'Remis.' : (state.result === '1-0' ? whiteName : blackName) + ' gewinnt.') | |
| : paused ? 'Pausiert.' : (state.moves.length % 2 ? blackName : whiteName) + ' ist am Zug.'; | |
| return; | |
| } | |
| statusText.textContent = state.result ? ({'1-0':'Du hast gewonnen.','0-1':state.engine_name + ' gewinnt.','1/2-1/2':'Remis.'}[state.result]) : state.check ? 'Schach. Du bist am Zug.' : 'Du bist am Zug.'; | |
| } | |
| async function click(square) { | |
| unlockSound(); | |
| if (watching || busy || state.result) return; | |
| const candidates = state.legal.filter(move => move.startsWith(selected + square)); | |
| if (!candidates.length) { | |
| selected = state.legal.some(move => move.startsWith(square)) && selected !== square ? square : undefined; | |
| draw(); | |
| return; | |
| } | |
| busy = true; | |
| reset.disabled = true; | |
| try { | |
| let move = candidates[0]; | |
| if (candidates.length > 1) { | |
| promotion.returnValue = ''; | |
| promotion.showModal(); | |
| const piece = await new Promise(resolve => promotion.addEventListener('close', () => resolve(promotion.returnValue), {once:true})); | |
| move = candidates.find(candidate => candidate.endsWith(piece) && piece); | |
| if (!move) return; | |
| } | |
| statusText.textContent = state.engine_name + ' ist am Zug …'; | |
| const previousLength = state.moves.length; | |
| state = await request([...state.moves, move]); | |
| selected = undefined; | |
| draw(); | |
| const played = state.moves.length - previousLength; | |
| state.sounds.slice(-played).forEach((kind, index) => playSound(kind, index * .14)); | |
| if (state.result) playSound('end', played * .14); | |
| } catch (error) { | |
| statusText.textContent = error.message; | |
| } finally { | |
| busy = false; | |
| reset.disabled = false; | |
| } | |
| } | |
| reset.onclick = async () => { | |
| if (busy) return; | |
| clearTimeout(timer); | |
| busy = true; | |
| try { | |
| if (pondering) { | |
| if (ponderGame) await request({game: ponderGame}, '/ponder-stop'); | |
| ponderGame = crypto.randomUUID(); | |
| } | |
| state = await request(); | |
| selected = undefined; | |
| paused = false; | |
| pause.textContent = 'Pausieren'; | |
| draw(); | |
| } | |
| catch (error) { statusText.textContent = error.message; } | |
| finally { busy = false; } | |
| if (watching) scheduleMove(); | |
| }; | |
| function scheduleMove() { | |
| clearTimeout(timer); | |
| if (state && !paused && !state.result && !busy) timer = setTimeout(nextMove, 850); | |
| } | |
| async function nextMove() { | |
| busy = true; | |
| reset.disabled = true; | |
| try { | |
| state = pondering | |
| ? await request({game: ponderGame, moves: state.moves}, '/match-ponder') | |
| : await request(state.moves, proDuel ? (proBlack ? '/match-pro-black' : '/match-pro') : strong ? '/match-max' : '/match'); | |
| if (pondering && paused) await request({game: ponderGame}, '/ponder-stop'); | |
| draw(); | |
| playSound(state.sounds.at(-1)); | |
| if (state.result) playSound('end', .14); | |
| } catch (error) { | |
| paused = true; | |
| pause.textContent = 'Fortsetzen'; | |
| statusText.textContent = error.message; | |
| } finally { | |
| busy = false; | |
| reset.disabled = false; | |
| } | |
| scheduleMove(); | |
| } | |
| pause.onclick = () => { | |
| if (!state || state.result) return; | |
| unlockSound(); | |
| paused = !paused; | |
| if (pondering && paused && !busy) request({game: ponderGame}, '/ponder-stop').catch(() => {}); | |
| pause.textContent = paused ? 'Fortsetzen' : 'Pausieren'; | |
| draw(); | |
| scheduleMove(); | |
| }; | |
| if (pondering) addEventListener('pagehide', () => { | |
| if (ponderGame) fetch('/ponder-stop', {method:'POST', keepalive:true, | |
| headers:{'Content-Type':'application/json'}, body:JSON.stringify({game: ponderGame})}).catch(() => {}); | |
| }); | |
| reset.click(); | |
| </script> | |
| </html> | |