Engine is a UCI interface between an engine executable (that understands UCI) and itself. It abstracts away communication to the engine process by providing methods for sending commands and mechanisms for parsing responses.

It also has a chainable api (EngineChain) that allows for terse coding.

Implements everything in the UCI protocol except debug and registration.

commands to engine
  • ✓ uci
  • ✗ debug
  • ✓ isready
  • ✓ setoption
  • ✗ register
  • ✓ ucinewgame
  • ✓ position
  • ✓ go
  • ✓ stop
  • ✓ ponderhit
  • ✓ quit
responses from engine
  • ✓ id
  • ✓ uciok
  • ✓ readyok
  • ✓ bestmove [ ponder]
  • ✗ copyprotection
  • ✗ registration
  • ✓ info
  • ✓ option
new Engine(filePath: string)
Parameters
filePath (string) absolute path to engine executable
Example
const enginePath = '/some/place/here'
//async/await
const engine = new Engine(enginePath)
await engine.init()
await engine.setoption('MultiPV', '4')
await engine.isready()
console.log('engine ready', engine.id, engine.options)
const result = await engine.go({depth: 4})
console.log('result', result)
await engine.quit()

//with chain api
const engine = new Engine(enginePath)
engine.chain()
.init()
.setoption('MultiPV', 3)
.position('r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R b KQkq - 3 3')
.go({depth: 15})
.then(result => {
  console.log('result', result)
})
Instance Members
getBufferUntil(condition)
write(command)
chain()
init()
quit()
isready()
sendCmd(cmd)
setoption(name, value?)
ucinewgame()
ponderhit()
position(fen, moves)
go(options)
goInfinite(options)
stop()

EngineChain sets up an api to enable chaining when dealing with Engines.

chainable methods
  • init
  • setoption
  • isready
  • ucinewgame
  • quit
  • position
  • go

go is a special case that ends the chain by calling #EngineChain#exec, and returns the search result.

new EngineChain(engine: Engine)
Parameters
engine (Engine) an instance of Engine
Example
const engine = new Engine(enginePath)
const chain = new EngineChain(engine)
// OR: const chain = engine.chain()
.init()
.setoption('MultiPV', 3)
.position('r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R b KQkq - 3 3')
.go({depth: 15})
.then(result => {
  console.log('result', result)
})
Instance Members
exec()