}
};
+// returns the version of the Fairy-Stockfish binary
+std::string info() {
+ return engine_info();
+}
+
bool Board::sfInitialized = false;
// binding code
EMSCRIPTEN_BINDINGS(ffish_js) {
+ function("info", &info);
class_<Board>("Board")
.constructor<>()
.constructor<std::string>()
# ffish.js
-**ffish.js** is a high performance JavaScript library which supports all chess variants of _FairyStockfish_.
+A high performance WebAssembly chess variant library based on _Fairy-Stockfish_.
It is built using emscripten/Embind from C++ source code.
* https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html
+## Install instructions
+
+```bash
+npm install ffish
+```
+
## Build instuctions
```bash
-cd ../../src
+cd Fairy-Stockfish/src
```
```bash
emcc -O3 --bind ffishjs.cpp \
Load the API in JavaScript:
```javascript
-const ffish = require('./ffish.js');
+const ffish = require('ffish');
```
Create a new variant board from its default starting position:
```bash
node index.js
```
+
+## Compile as ES6/ES2015 module
+
+Some environments such as [vue-js](https://vuejs.org/) may require the library to be exported
+ as a ES6/ES2015 module.
+
+```bash
+cd Fairy-Stockfish/src
+```
+```bash
+emcc -O3 --bind \
+-s ENVIRONMENT='web,worker' -s EXPORT_ES6=1 -s MODULARIZE=1 -s USE_ES6_IMPORT_META=0 \
+ffishjs.cpp \
+benchmark.cpp \
+bitbase.cpp \
+bitboard.cpp \
+endgame.cpp \
+evaluate.cpp \
+material.cpp \
+misc.cpp \
+movegen.cpp \
+movepick.cpp \
+parser.cpp \
+partner.cpp \
+pawns.cpp \
+piece.cpp \
+position.cpp \
+psqt.cpp \
+search.cpp \
+thread.cpp \
+timeman.cpp \
+tt.cpp \
+uci.cpp \
+syzygy/tbprobe.cpp \
+ucioption.cpp \
+variant.cpp \
+xboard.cpp \
+-o ../tests/js/ffish.js
+```
+
+Later the module can be imported as follows:
+
+```javascript
+import Module from './ffish.js';
+let ffish = null;
+
+new Module().then(loadedModule => {
+ ffish = loadedModule;
+ console.log(`initialized ${ffish} ${loadedModule}`);
+ }
+});
+
+```
+References: [emscripten/#10114](https://github.com/emscripten-core/emscripten/issues/10114)
{
- "name": "ffish_test",
- "version": "1.0.0",
- "description": "Testing server for ffish.js",
- "main": "index.js",
+ "name": "ffish",
+ "version": "0.1.4",
+ "description": "A high performance WebAssembly chess variant library based on Fairy-Stockfish",
+ "main": "ffish.js",
"scripts": {
- "test": "mocha"
+ "test": "mocha",
+ "dev": "node index"
},
- "author": "Fabian Fichter, Johannes Czech",
+ "author": [
+ {
+ "name": "Fabian Fichter",
+ "url": "https://github.com/ianfab"
+ },
+ {
+ "name": "Johannes Czech",
+ "url": "https://github.com/QueensGambit"
+ }
+ ],
+ "keywords": ["wasm", "library", "chess-variants", "fairy-stockfish"],
"license": "GPL-3.0",
- "dependencies": {
+ "homepage": "https://github.com/ianfab/Fairy-Stockfish/tree/master/tests/js#readme",
+ "dependencies": {},
+ "devDependencies": {
+ "chai": "^4.2.0",
"chess": "^0.4.3",
"chess.js": "^0.11.0",
"crazyhouse.js": "0.0.8",
"express": "^4.17.1",
+ "mocha": "^8.0.1",
"performance": "^1.4.0"
- },
- "devDependencies": {
- "chai": "^4.2.0",
- "mocha": "^8.0.1"
}
}
chai.expect(board.isGameOver()).to.equal(true);
});
});
+
+describe('ffish.info()', function () {
+ it("it returns the version of the Fairy-Stockfish binary", () => {
+ chai.expect(ffish.info()).to.be.a('string');
+ });
+});