Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stockfish.wasm

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stockfish.wasm

WebAssembly port of the strong chess engine Stockfish

  • 0.4.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
238
increased by23.96%
Maintainers
1
Weekly downloads
 
Created
Source

stockfish.wasm

WebAssembly port of the strong chess engine Stockfish. See it in action on https://lichess.org/analysis.

npm version

Requirements

Uses the latest WebAssembly threading proposal.

  • Available as an Origin Trial in Chrome 70.
  • Behind a flag since Chrome 70: chrome://flags/#enable-webassembly-threads
  • Behind a flag in Firefox Nightly: javascript.options.shared_memory in about:config.

See stockfish.js for a more portable but single-threaded version.

Feature detection:

function wasmThreadsSupported() {
  // WebAssembly 1.0
  var source = Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00);
  if (typeof WebAssembly !== 'object' || !WebAssembly.validate(source)) return false;

  // SharedArrayBuffer
  if (typeof SharedArrayBuffer !== 'function') return false;

  // Atomics
  if (typeof Atomics !== 'object') return false;

  // Shared memory
  if (!(new WebAssembly.Memory({shared: true, initial: 8, maximum: 8}).buffer instanceof SharedArrayBuffer)) return false;

  // Structured cloning
  try {
    // You have to make sure nobody cares about this message!
    window.postMessage(new WebAssembly.Module(source), '*');
  } catch (e) {
    return false;
  }

  return true;
}

Limitations

  • Maximum number of threads determined at compile time (currently 8).
  • Maximum size of hashtable determined at compile time (currently 16 MB).
  • No Syzygy tablebase support.
  • Exposed as a global variable in JavaScript (window.Module), only one instance per site.

Building

Assuming em++ is available:

npm run-script prepare

Usage

Requires stockfish.js, stockfish.wasm, stockfish.js.mem and stockfish.worker.js (total size ~600K) to be served from the same directory.

<script src="stockfish.js"></script>
<script>
Module.addMessageListener(function (line) {
  console.log(line);
});

Module.postMessage('uci');
</script>

License

Thanks to the Stockfish team for sharing the engine under the GPL3.

Keywords

FAQs

Package last updated on 04 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc