An open API service indexing awesome lists of open source software.

https://github.com/shahradelahi/node-stockfish

♟️ Stockfish 17.1 WASM chess engine for Node.js with UCI and analysis.
https://github.com/shahradelahi/node-stockfish

analysis chess engine fen nodejs stockfish typescript uci wasm

Last synced: 5 months ago
JSON representation

♟️ Stockfish 17.1 WASM chess engine for Node.js with UCI and analysis.

Awesome Lists containing this project

README

          



Stockfish



Stockfish for Node.JS




CI


NPM Version


GPL-3.0 License

npm bundle size

Install Size

_@se-oss/stockfish_ is a high-performance, TypeScript-first Node.js wrapper for the Stockfish 17.1 WASM chess engine. It provides a convenient API for integrating powerful chess analysis capabilities into your applications, offering functionalities such as position analysis, best move calculation, and direct UCI command interaction.

---

- [Installation](#-installation)
- [Usage](#-usage)
- [Documentation](#-documentation)
- [Contributing](#-contributing)
- [License](#license)

## 📦 Installation

```bash
npm i @se-oss/stockfish
```

Install using your favorite package manager

**pnpm**

```bash
pnpm install @se-oss/stockfish
```

**yarn**

```bash
yarn add @se-oss/stockfish
```

## 📖 Usage

### Basic Analysis

```typescript
import { Stockfish } from '@se-oss/stockfish';

const engine = new Stockfish();
await engine.waitReady();

const analysis = await engine.analyze(
'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1',
15
);

console.log('Best move:', analysis.bestmove); // e2e4
console.log('Score:', analysis.lines[0].score); // { type: 'cp', value: 39 }
```

### Advanced UCI Commands

```typescript
const engine = new Stockfish();

engine.on('info', (info) => {
console.log(`Depth ${info.depth}: ${info.pv}`);
});

await engine.send('uci');
await engine.send('isready');
await engine.send('position startpos moves e2e4');
await engine.send('go depth 20');
```

### Using the Stockfish Pool

```typescript
import { StockfishPool } from '@se-oss/stockfish';

const pool = new StockfishPool(4); // Create a pool with 4 engine instances
await pool.initialize();

// Acquire an engine, use it, and release it back to the pool
const engine = await pool.acquire();
console.log('Engine acquired');
const analysis = await engine.analyze(
'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1',
10
);
console.log('Best move from pool engine:', analysis.bestmove);
pool.release(engine);
console.log('Engine released');

// Terminate the pool when done
pool.terminate();
```

## 📚 Documentation

For detailed API documentation on all methods, please see [the API docs](https://www.jsdocs.io/package/@se-oss/stockfish).

## 🤝 Contributing

Want to contribute? Awesome! To show your support is to star the project, or to raise issues on [GitHub](https://github.com/shahradelahi/node-stockfish).

## License

[GPL-3.0](/LICENSE) © [Shahrad Elahi](https://github.com/shahradelahi) and [contributors](https://github.com/shahradelahi/node-stockfish/graphs/contributors).