node-uci
Version:
Universal Chess Interface protocol implementation for node.js
1,679 lines (855 loc) • 53.1 kB
HTML
<!doctype html>
<html lang="en">
<head>
<meta charset='utf-8'>
<title>node-uci 1.3.2 | Documentation</title>
<meta name='description' content='Universal Chess Interface protocol implementation for node.js'>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<link href='assets/bass.css' rel='stylesheet'>
<link href='assets/style.css' rel='stylesheet'>
<link href='assets/github.css' rel='stylesheet'>
<link href='assets/split.css' rel='stylesheet'>
</head>
<body class='documentation m0'>
<div class='flex'>
<div id='split-left' class='overflow-auto fs0 height-viewport-100'>
<div class='py1 px2'>
<h3 class='mb0 no-anchor'>node-uci</h3>
<div class='mb1'><code>1.3.2</code></div>
<input
placeholder='Filter'
id='filter-input'
class='col12 block input'
type='text' />
<div id='toc'>
<ul class='list-reset h5 py1-ul'>
<li><a
href='#engine'
class=" toggle-sibling">
Engine
<span class='icon'>▸</span>
</a>
<div class='toggle-target display-none'>
<ul class='list-reset py1-ul pl1'>
<li class='h5'><span>Instance members</span></li>
<li><a
href='#enginegetbufferuntil'
class='regular pre-open'>
#getBufferUntil
</a></li>
<li><a
href='#enginewrite'
class='regular pre-open'>
#write
</a></li>
<li><a
href='#enginechain'
class='regular pre-open'>
#chain
</a></li>
<li><a
href='#engineinit'
class='regular pre-open'>
#init
</a></li>
<li><a
href='#enginequit'
class='regular pre-open'>
#quit
</a></li>
<li><a
href='#engineisready'
class='regular pre-open'>
#isready
</a></li>
<li><a
href='#enginesendcmd'
class='regular pre-open'>
#sendCmd
</a></li>
<li><a
href='#enginesetoption'
class='regular pre-open'>
#setoption
</a></li>
<li><a
href='#engineucinewgame'
class='regular pre-open'>
#ucinewgame
</a></li>
<li><a
href='#engineponderhit'
class='regular pre-open'>
#ponderhit
</a></li>
<li><a
href='#engineposition'
class='regular pre-open'>
#position
</a></li>
<li><a
href='#enginego'
class='regular pre-open'>
#go
</a></li>
<li><a
href='#enginegoinfinite'
class='regular pre-open'>
#goInfinite
</a></li>
<li><a
href='#enginestop'
class='regular pre-open'>
#stop
</a></li>
</ul>
</div>
</li>
<li><a
href='#enginechain'
class=" toggle-sibling">
EngineChain
<span class='icon'>▸</span>
</a>
<div class='toggle-target display-none'>
<ul class='list-reset py1-ul pl1'>
<li class='h5'><span>Instance members</span></li>
<li><a
href='#enginechainexec'
class='regular pre-open'>
#exec
</a></li>
</ul>
</div>
</li>
</ul>
</div>
<div class='mt1 h6 quiet'>
<a href='https://documentation.js.org/reading-documentation.html'>Need help reading this?</a>
</div>
</div>
</div>
<div id='split-right' class='relative overflow-auto height-viewport-100'>
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<h3 class='fl m0' id='engine'>
Engine
</h3>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/ebemunk/node-uci/blob/7da2216b49ac1f575a042d033013a2ac09e1b650/src/Engine/index.js#L81-L484'>
<span>src/Engine/index.js</span>
</a>
</div>
<p>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.</p>
<p>It also has a chainable api (<a href="#enginechain">EngineChain</a>) that allows for terse coding.</p>
<p>Implements everything in the UCI protocol except debug and registration.</p>
<h5>commands to engine</h5>
<ul>
<li>✓ uci</li>
<li>✗ debug</li>
<li>✓ isready</li>
<li>✓ setoption</li>
<li>✗ register</li>
<li>✓ ucinewgame</li>
<li>✓ position</li>
<li>✓ go</li>
<li>✓ stop</li>
<li>✓ ponderhit</li>
<li>✓ quit</li>
</ul>
<h5>responses from engine</h5>
<ul>
<li>✓ id</li>
<li>✓ uciok</li>
<li>✓ readyok</li>
<li>✓ bestmove [ ponder]</li>
<li>✗ copyprotection</li>
<li>✗ registration</li>
<li>✓ info</li>
<li>✓ option</li>
</ul>
<div class='pre p1 fill-light mt0'>new Engine(filePath: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>)</div>
<div class='py1 quiet mt1 prose-big'>Parameters</div>
<div class='prose'>
<div class='space-bottom0'>
<div>
<span class='code bold'>filePath</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>)</code>
absolute path to engine executable
</div>
</div>
</div>
<div class='py1 quiet mt1 prose-big'>Example</div>
<pre class='p1 overflow-auto round fill-light'><span class="hljs-keyword">const</span> enginePath = <span class="hljs-string">'/some/place/here'</span>
<span class="hljs-comment">//async/await</span>
<span class="hljs-keyword">const</span> engine = <span class="hljs-keyword">new</span> Engine(enginePath)
<span class="hljs-keyword">await</span> engine.init()
<span class="hljs-keyword">await</span> engine.setoption(<span class="hljs-string">'MultiPV'</span>, <span class="hljs-string">'4'</span>)
<span class="hljs-keyword">await</span> engine.isready()
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'engine ready'</span>, engine.id, engine.options)
<span class="hljs-keyword">const</span> result = <span class="hljs-keyword">await</span> engine.go({<span class="hljs-attr">depth</span>: <span class="hljs-number">4</span>})
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'result'</span>, result)
<span class="hljs-keyword">await</span> engine.quit()
<span class="hljs-comment">//with chain api</span>
<span class="hljs-keyword">const</span> engine = <span class="hljs-keyword">new</span> Engine(enginePath)
engine.chain()
.init()
.setoption(<span class="hljs-string">'MultiPV'</span>, <span class="hljs-number">3</span>)
.position(<span class="hljs-string">'r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R b KQkq - 3 3'</span>)
.go({<span class="hljs-attr">depth</span>: <span class="hljs-number">15</span>})
.then(<span class="hljs-function"><span class="hljs-params">result</span> =></span> {
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'result'</span>, result)
})</pre>
<div class='py1 quiet mt1 prose-big'>Instance Members</div>
<div class="clearfix">
<div class='border-bottom' id='enginegetbufferuntil'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>getBufferUntil(condition)</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/ebemunk/node-uci/blob/7da2216b49ac1f575a042d033013a2ac09e1b650/src/Engine/index.js#L118-L153'>
<span>src/Engine/index.js</span>
</a>
</div>
<p>Retireve the proc buffer until condition is true.
You shouldn't need to use this normally.</p>
<div class='pre p1 fill-light mt0'>getBufferUntil(condition: function (<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>)): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a><<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>>></div>
<div class='py1 quiet mt1 prose-big'>Parameters</div>
<div class='prose'>
<div class='space-bottom0'>
<div>
<span class='code bold'>condition</span> <code class='quiet'>(function (<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>))</code>
a function that returns true at some point
</div>
</div>
</div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a><<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>>></code>:
array of strings containing buffer received from engine
<div class='py1 quiet mt1 prose-big'>Example</div>
<pre class='p1 overflow-auto round fill-light'><span class="hljs-comment">//async/await</span>
<span class="hljs-keyword">const</span> lines = <span class="hljs-keyword">await</span> myEngine.getBufferUntil(<span class="hljs-function"><span class="hljs-params">line</span> =></span> line === <span class="hljs-string">'uciok'</span>)
<span class="hljs-comment">//promise</span>
myEngine.getBufferUntil(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">line</span>) </span>{
<span class="hljs-keyword">return</span> line === <span class="hljs-string">'uciok'</span>
})
.then(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">lines</span>) </span>{
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'engine says'</span>, lines)
})</pre>
</section>
</div>
</div>
<div class='border-bottom' id='enginewrite'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>write(command)</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/ebemunk/node-uci/blob/7da2216b49ac1f575a042d033013a2ac09e1b650/src/Engine/index.js#L161-L164'>
<span>src/Engine/index.js</span>
</a>
</div>
<p>Writes command to engine process. Normally you shouldn't need to use this.
Does not validate string, use with caution or engine may have undefined behavior.</p>
<div class='pre p1 fill-light mt0'>write(command: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined">undefined</a></div>
<div class='py1 quiet mt1 prose-big'>Parameters</div>
<div class='prose'>
<div class='space-bottom0'>
<div>
<span class='code bold'>command</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>)</code>
command to write to engine process' stdin
</div>
</div>
</div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined">undefined</a></code>:
has no return value
</section>
</div>
</div>
<div class='border-bottom' id='enginechain'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>chain()</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/ebemunk/node-uci/blob/7da2216b49ac1f575a042d033013a2ac09e1b650/src/Engine/index.js#L176-L178'>
<span>src/Engine/index.js</span>
</a>
</div>
<p>Returns a new <a href="#enginechain">EngineChain</a> using this engine.</p>
<div class='pre p1 fill-light mt0'>chain(): <a href="#enginechain">EngineChain</a></div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code><a href="#enginechain">EngineChain</a></code>:
new instance of
<a href="#enginechain">EngineChain</a>
<div class='py1 quiet mt1 prose-big'>Example</div>
<pre class='p1 overflow-auto round fill-light'><span class="hljs-keyword">const</span> chain = myEngine.chain()
<span class="hljs-comment">//equivalent to</span>
<span class="hljs-keyword">const</span> myEngine = <span class="hljs-keyword">new</span> Engine(myPath)
<span class="hljs-keyword">const</span> chain = <span class="hljs-keyword">new</span> EngineChain(myEngine)</pre>
</section>
</div>
</div>
<div class='border-bottom' id='engineinit'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>init()</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/ebemunk/node-uci/blob/7da2216b49ac1f575a042d033013a2ac09e1b650/src/Engine/index.js#L199-L223'>
<span>src/Engine/index.js</span>
</a>
</div>
<p>Initializes the engine process and handshakes with the UCI protocol.
When this is done, <a href="#Engine#id">#Engine#id</a> and <a href="#Engine#options">#Engine#options</a> are populated.</p>
<div class='pre p1 fill-light mt0'>init(): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><<a href="#engine">Engine</a>></div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><<a href="#engine">Engine</a>></code>:
itself (the Engine instance)
<div class='py1 quiet mt1 prose-big'>Throws</div>
<ul>
<li><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>: if init() has already been called (i.e Engine.proc is defined)
</li>
</ul>
<div class='py1 quiet mt1 prose-big'>Example</div>
<pre class='p1 overflow-auto round fill-light'><span class="hljs-comment">//async/await</span>
<span class="hljs-keyword">const</span> engine = <span class="hljs-keyword">new</span> Engine(somePath)
<span class="hljs-keyword">await</span> engine.init()
<span class="hljs-comment">//engine is initialized, do stuff...</span>
<span class="hljs-comment">//promise</span>
<span class="hljs-keyword">var</span> myEngine = <span class="hljs-keyword">new</span> Engine(somePath)
myEngine.init()
.then(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">engine</span>) </span>{
<span class="hljs-comment">//myEngine === engine</span>
<span class="hljs-comment">//do stuff</span>
})</pre>
</section>
</div>
</div>
<div class='border-bottom' id='enginequit'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>quit()</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/ebemunk/node-uci/blob/7da2216b49ac1f575a042d033013a2ac09e1b650/src/Engine/index.js#L230-L243'>
<span>src/Engine/index.js</span>
</a>
</div>
<p>Sends a quit message to the engine process, and cleans up.</p>
<div class='pre p1 fill-light mt0'>quit(): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><<a href="#engine">Engine</a>></div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><<a href="#engine">Engine</a>></code>:
itself (the Engine instance)
<div class='py1 quiet mt1 prose-big'>Throws</div>
<ul>
<li><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>: if engine process is not running (i.e. Engine.proc is undefined)
</li>
</ul>
</section>
</div>
</div>
<div class='border-bottom' id='engineisready'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>isready()</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/ebemunk/node-uci/blob/7da2216b49ac1f575a042d033013a2ac09e1b650/src/Engine/index.js#L250-L257'>
<span>src/Engine/index.js</span>
</a>
</div>
<p>Sends UCI <code>isready</code> command to the engine. Promise resolves after <code>readyok</code> is received.</p>
<div class='pre p1 fill-light mt0'>isready(): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><<a href="#engine">Engine</a>></div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><<a href="#engine">Engine</a>></code>:
itself (the Engine instance)
<div class='py1 quiet mt1 prose-big'>Throws</div>
<ul>
<li><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>: if Engine process is not running
</li>
</ul>
</section>
</div>
</div>
<div class='border-bottom' id='enginesendcmd'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>sendCmd(cmd)</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/ebemunk/node-uci/blob/7da2216b49ac1f575a042d033013a2ac09e1b650/src/Engine/index.js#L267-L276'>
<span>src/Engine/index.js</span>
</a>
</div>
<p>Sends a command to engine process. Promise resolves after <code>readyok</code> is received.
Some commands in the UCI protocol do not require responses (like <code>setoption</code>).
So, to be sure, <a href="#engineisready">Engine#isready</a> is invoked to determine when it's safe to continue.</p>
<div class='pre p1 fill-light mt0'>sendCmd(cmd: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><<a href="#engine">Engine</a>></div>
<div class='py1 quiet mt1 prose-big'>Parameters</div>
<div class='prose'>
<div class='space-bottom0'>
<div>
<span class='code bold'>cmd</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>)</code>
command to send to the engine process
</div>
</div>
</div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><<a href="#engine">Engine</a>></code>:
itself (the Engine instance)
<div class='py1 quiet mt1 prose-big'>Throws</div>
<ul>
<li><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>: if engine process is not running
</li>
</ul>
</section>
</div>
</div>
<div class='border-bottom' id='enginesetoption'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>setoption(name, value?)</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/ebemunk/node-uci/blob/7da2216b49ac1f575a042d033013a2ac09e1b650/src/Engine/index.js#L302-L310'>
<span>src/Engine/index.js</span>
</a>
</div>
<p>Sends the <code>setoption</code> command for given option name and its value.
Does not validate parameters. <code>value</code>, if given, is coerced into a string.</p>
<div class='pre p1 fill-light mt0'>setoption(name: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>, value: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>?): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><<a href="#engine">Engine</a>></div>
<div class='py1 quiet mt1 prose-big'>Parameters</div>
<div class='prose'>
<div class='space-bottom0'>
<div>
<span class='code bold'>name</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>)</code>
name of the option property
</div>
</div>
<div class='space-bottom0'>
<div>
<span class='code bold'>value</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>?)</code>
value of the option
</div>
</div>
</div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><<a href="#engine">Engine</a>></code>:
itself (the Engine instance)
<div class='py1 quiet mt1 prose-big'>Throws</div>
<ul>
<li><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>: if engine process is not running
</li>
</ul>
<div class='py1 quiet mt1 prose-big'>Example</div>
<pre class='p1 overflow-auto round fill-light'><span class="hljs-comment">//async/await</span>
<span class="hljs-keyword">await</span> myEngine.setoption(<span class="hljs-string">'MultiPV'</span>, <span class="hljs-string">'3'</span>)
<span class="hljs-keyword">await</span> myEngine.setoption(<span class="hljs-string">'Slow Mover'</span>, <span class="hljs-string">'400'</span>)
<span class="hljs-built_in">console</span>.log(myEngine.options)
<span class="hljs-comment">// -> output includes newly set options</span>
<span class="hljs-comment">//promise</span>
myEngine.setoption(<span class="hljs-string">'MultiPV'</span>, <span class="hljs-string">'3'</span>)
.then(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">engine</span>) </span>{
<span class="hljs-keyword">return</span> engine.setoption(<span class="hljs-string">'Slow Mover'</span>, <span class="hljs-string">'400'</span>);
})
.then(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">engine</span>) </span>{
<span class="hljs-built_in">console</span>.log(myEngine.options)
<span class="hljs-comment">// -> output includes newly set options</span>
})</pre>
</section>
</div>
</div>
<div class='border-bottom' id='engineucinewgame'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>ucinewgame()</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/ebemunk/node-uci/blob/7da2216b49ac1f575a042d033013a2ac09e1b650/src/Engine/index.js#L317-L319'>
<span>src/Engine/index.js</span>
</a>
</div>
<p>Sends <code>ucinewgame</code> command to engine process.</p>
<div class='pre p1 fill-light mt0'>ucinewgame(): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><<a href="#engine">Engine</a>></div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><<a href="#engine">Engine</a>></code>:
itself (the Engine instance)
<div class='py1 quiet mt1 prose-big'>Throws</div>
<ul>
<li><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>: if engine process is not running
</li>
</ul>
</section>
</div>
</div>
<div class='border-bottom' id='engineponderhit'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>ponderhit()</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/ebemunk/node-uci/blob/7da2216b49ac1f575a042d033013a2ac09e1b650/src/Engine/index.js#L326-L328'>
<span>src/Engine/index.js</span>
</a>
</div>
<p>Sends <code>ponderhit</code> command to engine process.</p>
<div class='pre p1 fill-light mt0'>ponderhit(): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><<a href="#engine">Engine</a>></div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><<a href="#engine">Engine</a>></code>:
itself (the Engine instance)
<div class='py1 quiet mt1 prose-big'>Throws</div>
<ul>
<li><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>: if engine process is not running
</li>
</ul>
</section>
</div>
</div>
<div class='border-bottom' id='engineposition'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>position(fen, moves)</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/ebemunk/node-uci/blob/7da2216b49ac1f575a042d033013a2ac09e1b650/src/Engine/index.js#L339-L354'>
<span>src/Engine/index.js</span>
</a>
</div>
<p>Sends <code>position</code> command to engine process.
Does not validate inputs.</p>
<div class='pre p1 fill-light mt0'>position(fen: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>, moves: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a><<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>>): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><<a href="#engine">Engine</a>></div>
<div class='py1 quiet mt1 prose-big'>Parameters</div>
<div class='prose'>
<div class='space-bottom0'>
<div>
<span class='code bold'>fen</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>)</code>
can be
<code>startpos</code>
for start position, or
<code>fen ...</code>
for
setting position via FEN
</div>
</div>
<div class='space-bottom0'>
<div>
<span class='code bold'>moves</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a><<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>>)</code>
moves (in engine notation) to append to the command
</div>
</div>
</div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><<a href="#engine">Engine</a>></code>:
itself (the Engine instance)
<div class='py1 quiet mt1 prose-big'>Throws</div>
<ul>
<li><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>: if engine process is not running
</li>
</ul>
</section>
</div>
</div>
<div class='border-bottom' id='enginego'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>go(options)</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/ebemunk/node-uci/blob/7da2216b49ac1f575a042d033013a2ac09e1b650/src/Engine/index.js#L397-L412'>
<span>src/Engine/index.js</span>
</a>
</div>
<p>Sends the <code>go</code> command to the engine process. Returns after engine finds the best move.
Does not validate options. Does not work for infinite search. For intinite search, see <a href="#Engine#goInfinite">#Engine#goInfinite</a>.
Options have identical names as the UCI <code>go</code> options. See UCI protocol for information.
On completion, it returns an object containing the <code>bestmove</code> and an array of <code>info</code> objects,
these <code>info</code> objects have properties that correspond to the UCI protocol.</p>
<div class='pre p1 fill-light mt0'>go(options: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a>): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><{bestmove: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>, info: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a><<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>>}></div>
<div class='py1 quiet mt1 prose-big'>Parameters</div>
<div class='prose'>
<div class='space-bottom0'>
<div>
<span class='code bold'>options</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a>)</code>
options
</div>
<table class='mt1 mb2 fixed-table h5 col-12'>
<colgroup>
<col width='30%' />
<col width='70%' />
</colgroup>
<thead>
<tr class='bold fill-light'>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody class='mt1'>
<tr>
<td class='break-word'><span class='code bold'>options.searchmoves</span> <code class='quiet'><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a><<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>></code>
</td>
<td class='break-word'><span>moves (in engine notation) to search for
</span></td>
</tr>
<tr>
<td class='break-word'><span class='code bold'>options.ponder</span> <code class='quiet'><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code>
</td>
<td class='break-word'><span>ponder mode
</span></td>
</tr>
<tr>
<td class='break-word'><span class='code bold'>options.wtime</span> <code class='quiet'><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code>
</td>
<td class='break-word'><span>wtime (integer > 0)
</span></td>
</tr>
<tr>
<td class='break-word'><span class='code bold'>options.btime</span> <code class='quiet'><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code>
</td>
<td class='break-word'><span>btime (integer > 0)
</span></td>
</tr>
<tr>
<td class='break-word'><span class='code bold'>options.winc</span> <code class='quiet'><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code>
</td>
<td class='break-word'><span>winc (integer > 0)
</span></td>
</tr>
<tr>
<td class='break-word'><span class='code bold'>options.binc</span> <code class='quiet'><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code>
</td>
<td class='break-word'><span>binc (integer > 0)
</span></td>
</tr>
<tr>
<td class='break-word'><span class='code bold'>options.movestogo</span> <code class='quiet'><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code>
</td>
<td class='break-word'><span>movestogo (integer > 0)
</span></td>
</tr>
<tr>
<td class='break-word'><span class='code bold'>options.depth</span> <code class='quiet'><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code>
</td>
<td class='break-word'><span>depth (integer > 0)
</span></td>
</tr>
<tr>
<td class='break-word'><span class='code bold'>options.nodes</span> <code class='quiet'><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code>
</td>
<td class='break-word'><span>nodes (integer > 0)
</span></td>
</tr>
<tr>
<td class='break-word'><span class='code bold'>options.mate</span> <code class='quiet'><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code>
</td>
<td class='break-word'><span>mate (integer > 0)
</span></td>
</tr>
<tr>
<td class='break-word'><span class='code bold'>options.movetime</span> <code class='quiet'><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code>
</td>
<td class='break-word'><span>movetime (integer > 0)
</span></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><{bestmove: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>, info: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a><<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>>}></code>:
result -
<code>bestmove</code>
string
and array of chronologically-ordered
<code>info</code>
objects
<div class='py1 quiet mt1 prose-big'>Throws</div>
<ul>
<li><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>: if engine process is not running
</li>
<li><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>: if
<code>infinite</code>
is supplied in the options param
</li>
</ul>
<div class='py1 quiet mt1 prose-big'>Example</div>
<pre class='p1 overflow-auto round fill-light'><span class="hljs-comment">//async/await</span>
<span class="hljs-keyword">const</span> engine = <span class="hljs-keyword">new</span> Engine(somePath)
<span class="hljs-keyword">await</span> engine.init()
<span class="hljs-keyword">const</span> result = <span class="hljs-keyword">await</span> engine.go({<span class="hljs-attr">depth</span>: <span class="hljs-number">3</span>})
<span class="hljs-built_in">console</span>.log(result)
<span class="hljs-comment">// -> {bestmove: 'e2e4', info: [{depth: 1, seldepth: 1, nodes: 21,...}, ...]}</span>
<span class="hljs-comment">//promise</span>
<span class="hljs-keyword">var</span> myEngine = <span class="hljs-keyword">new</span> Engine(somePath)
myEngine.init()
.then(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">engine</span>) </span>{
<span class="hljs-keyword">return</span> engine.go({<span class="hljs-attr">depth</span>: <span class="hljs-number">3</span>})
})
.then(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">result</span>) </span>{
<span class="hljs-built_in">console</span>.log(result)
<span class="hljs-comment">// -> {bestmove: 'e2e4', info: [{depth: 1, seldepth: 1, nodes: 21,...}, ...]}</span>
})</pre>
</section>
</div>
</div>
<div class='border-bottom' id='enginegoinfinite'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>goInfinite(options)</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/ebemunk/node-uci/blob/7da2216b49ac1f575a042d033013a2ac09e1b650/src/Engine/index.js#L437-L461'>
<span>src/Engine/index.js</span>
</a>
</div>
<p>Special case of <a href="#Engine#go">#Engine#go</a> with <code>infinite</code> search enabled.</p>
<div class='pre p1 fill-light mt0'>goInfinite(options: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a>): EventEmitter</div>
<div class='py1 quiet mt1 prose-big'>Parameters</div>
<div class='prose'>
<div class='space-bottom0'>
<div>
<span class='code bold'>options</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a>
= <code>{}</code>)</code>
options for search. see
<a href="#Engine#go">#Engine#go</a>
for details
</div>
</div>
</div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code>EventEmitter</code>:
an EventEmitter that will emit
<code>data</code>
events with either
<code>bestmove</code>
string or
<code>info</code>
objects.
<a href="#Engine#stop">#Engine#stop</a>
must be used to stop
the search and receive the bestmove.
<div class='py1 quiet mt1 prose-big'>Throws</div>
<ul>
<li><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>: if engine process is not running
</li>
</ul>
<div class='py1 quiet mt1 prose-big'>Example</div>
<pre class='p1 overflow-auto round fill-light'><span class="hljs-comment">//async/await</span>
<span class="hljs-keyword">const</span> engine = <span class="hljs-keyword">new</span> Engine(enginePath)
<span class="hljs-keyword">await</span> engine.init()
<span class="hljs-keyword">await</span> engine.isready()
<span class="hljs-keyword">await</span> engine.setoption(<span class="hljs-string">'MultiPV'</span>, <span class="hljs-string">'3'</span>)
<span class="hljs-keyword">const</span> emitter = engine.goInfinite()
emitter.on(<span class="hljs-string">'data'</span>, a => {
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'data'</span>, a)
})
setTimeout(<span class="hljs-keyword">async</span> () => {
<span class="hljs-keyword">const</span> bestmove = <span class="hljs-keyword">await</span> engine.stop()
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'bestmove'</span>, bestmove)
<span class="hljs-keyword">await</span> engine.quit()
}, <span class="hljs-number">5000</span>)</pre>
</section>
</div>
</div>
<div class='border-bottom' id='enginestop'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>stop()</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/ebemunk/node-uci/blob/7da2216b49ac1f575a042d033013a2ac09e1b650/src/Engine/index.js#L470-L483'>
<span>src/Engine/index.js</span>
</a>
</div>
<p>Sends <code>stop</code> command to the engine, for stopping an ongoing search. Engine will
reply with the <code>bestmove</code>, which is returned, along with any other <code>info</code> lines.
See <a href="#Engine#goInfinite">#Engine#goInfinite</a> for usage example.</p>
<div class='pre p1 fill-light mt0'>stop(): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><{bestmove: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>, info: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a><<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>>}></div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a><{bestmove: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>, info: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a><<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>>}></code>:
result - See
<a href="#Engine#go">#Engine#go</a>
</section>
</div>
</div>
</div>
</section>
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<h3 class='fl m0' id='enginechain'>
EngineChain
</h3>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/ebemunk/node-uci/blob/7da2216b49ac1f575a042d033013a2ac09e1b650/src/EngineChain/index.js#L45-L96'>
<span>src/EngineChain/index.js</span>
</a>
</div>
<p>EngineChain sets up an api to enable chaining when dealing with <a href="#engine">Engine</a>s.</p>
<h5>chainable methods</h5>
<ul>
<li>init</li>
<li>setoption</li>
<li>isready</li>
<li>ucinewgame</li>
<li>quit</li>
<li>position</li>
<li>go</li>
</ul>
<p><code>go</code> is a special c