Skip to content

Simple proof of concept to run Yaneuraou Engine from Web Browser

Notifications You must be signed in to change notification settings

a2life/shogi_engine_wasm_web_console

Repository files navigation

Simple WASM Yaneuraou engine console.

This HTML console uses WebAssembly version of Yaneuraou.
Its a simple proof of concept mock program to exercise the USI communication protocol of Yaneuraou Shogi engine on browser and ensure its functionality with HTML and JavaScript.

Operation of this source code was confirmed with halfkp.noeval version of YaneuraOu engine (various version 8.* and 7.6.3) with separately prepared Suisho5 Evaluation function binary as nn.bin, and yaneuraou Standard book(2017) as standard_book.db

To run this program,


/lib/yaneuraou.halfkp.noeval.js (and .br, .gz files)
/lib/yaneuraou.halfkp.noeval.wasm (and .br ,.gz files)
/eval/nn.bin
/book/standard_book.db
  • Run 'npm install'
  • Run 'npx server'

To obtain later versions of YaneuraOu engine,

WASM executable is not included in YaneuraOu release packages. Version 7.6.3 version is available from Mizar/Yaneuraou repo.

https://github.com/mizar/YaneuraOu/releases/tag/v7.6.3

In theory, we should be able to compile WebAssembly version of the Shogi engine from the source https://github.com/yaneurao/YaneuraOu with the following setup.

Note that WASM component for Version 9.x '_usi_command' export is currently turned off and not functional,so the compilation will fail.

  • Clone the source
  • Docker installed on your PC
  • just run .\script\build-wasm.cmd
  • to limit the compile target to halfkp.noeval, add 'halfkp.noeval' parameter in the last line of build-wasm.cmd. i.e.,

docker run --rm -v %CD%:/src emscripten/emsdk:3.1.43 node script/wasm_build.js halfkpi.noeval
  • This will compile the tournament version of Yaneuraou
  • If normal version is desired, search wasm_build.js for word 'tournament' and replace it with 'normal'

     `make -j${cpus} clean tournament COMPILER=em++ TARGET_CPU=WASM YANEURAOU_EDITION=${pkgobj.edition} TARGET=../${builddirlib}yaneuraou.${pkgobj.name}.js EM_EXPORT_NAME=${pkgobj.exportname} ${pkgobj.extra}`,
//change to 
    `make -j${cpus} clean normal COMPILER=em++ TARGET_CPU=WASM YANEURAOU_EDITION=${pkgobj.edition} TARGET=../${builddirlib}yaneuraou.${pkgobj.name}.js EM_EXPORT_NAME=${pkgobj.exportname} ${pkgobj.extra}`,
 

The generated WASM package includes javascript file that you can execute with node.js

In another word, included top level (usi.halfkp.noeval.js/ts) js file is meant for running the code locally on your PC. But why bother with this as you will get native binary for your machine anyway, (unless your machine's architecture is not supported)

The code in this repo (index.js and other js modules) will allow you to host this WASM files on a server so that remote browser will load them and run it inside the browser.

Just place files as below


/lib/yaneuraou.halfkp.noeval.js (and .br, .gz files)
/lib/yaneuraou.halfkp.noeval.wasm (and .br ,.gz files)
/eval/nn.bin
/book/standard_book.db

For testing it out, run npx serve. The web site can be viewed at http://localhost:3000

Note two additional http headers in serve.json. If served from NGINX or Apache server, you need to set these headers.

Concept recap (why these headers matter) To use SharedArrayBuffer on the open web, the page must be cross‑origin isolated, which means:

  • Cross-Origin-Opener-Policy: same-origin

  • Cross-Origin-Embedder-Policy: require-corp or credentialless

Once those are sent on your HTML + worker responses, SAB and high‑precision timers are unlocked in modern browsers.

You also want:

Correct Content-Type: application/wasm for .wasm

Compression (prefer .br, fallback .gz) for .wasm, nn.bin, book.db, etc.

Cross-Origin-Resource-Policy / CORS sane where needed.

About

Simple proof of concept to run Yaneuraou Engine from Web Browser

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published