Skip to content

Instantly share code, notes, and snippets.

@zamfofex
Last active February 19, 2022 10:59
Show Gist options
  • Save zamfofex/078a2bae37dbb60440093db30f816a63 to your computer and use it in GitHub Desktop.
Save zamfofex/078a2bae37dbb60440093db30f816a63 to your computer and use it in GitHub Desktop.
Dummyette UCI front end
*
!/.gitignore
!/readme.md
!/main.js
!/map.json

UCI front end for Dummyette

deno run --unstable --import-map=map.json -A main.js

GUI configuration

After installing Deno, you can set up your preferred GUI as follows:

  • Executable Path: deno
  • Working Directory: This Gist (cloned locally)
  • Command Line Arguments: run --unstable --import-map=map.json -A main.js
import {AsyncAnalyser} from "dummyette/dummyette.js"
import {standardBoard} from "dummyette/chess.js"
let understood = ["uci", "isready", "position", "go", "quit"]
let decoder = new TextDecoder()
let previous = []
let receive = async () =>
{
let bytes = []
outer:
while (true)
{
let buffer
let count
if (previous)
{
buffer = previous
count = buffer.length
previous = null
}
else
{
buffer = new Uint8Array(256)
count = await Deno.read(0, buffer)
if (count === null)
{
if (bytes.length === 0) return
else break
}
}
for (let i = 0 ; i < count ; i++)
{
if (buffer[i] === 0x0A || buffer[i] === 0x0D)
{
previous = buffer.slice(i + 1, count)
buffer = buffer.slice(0, i)
bytes.push(...buffer)
break outer
}
}
bytes.push(...buffer)
}
let text = decoder.decode(new Uint8Array(bytes))
let command = text.trim().split(/\s+/)
while (!understood.includes(command[0]))
command.shift()
return command
}
let board
let analyser
top:
while (true)
{
let command = await receive()
if (command === undefined) break
if (command.length === 0) continue
switch (command.shift())
{
default: break
case "quit":
break top
case "uci":
console.log("id name Dummyette")
console.log("uciok")
break
case "isready":
analyser = AsyncAnalyser()
console.log("readyok")
break
case "setoption":
{
if (command.shift() !== "name") break
let name = command.splice(0, command.findIndex(text => text !== "value")).join(" ").toLowerCase()
let value = command.join(" ").toLowerCase()
break
}
case "position":
if (command[0] === "startpos")
{
board = standardBoard
command.shift()
}
else if (command[0] === "fen")
{
command.shift()
let fen = command.shift()
close()
}
if (command.shift() === "moves")
{
for (let name of command)
board = board.play(name)
}
break
case "go":
{
let filter = () => true
outer:
while (true)
{
switch (command.shift())
{
default: break outer
case "searchmoves":
filter = ({name}) => command.includes(name)
break outer
case "ponder":
case "infinite":
break
case "wtime":
case "btime":
case "winc":
case "binc":
case "movestogo":
case "depth":
case "nodes":
case "mate":
case "movetime":
command.shift()
break
}
}
analyser.analyse(board).then(moves =>
{
moves = moves.filter(filter)
console.log(`bestmove ${moves[0].name}`)
})
break
}
}
}
close()
{
"imports":
{
"dummyette/": "https://raw.githubusercontent.com/zamfofex/dummyette/main/"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment