GithubHelp home page GithubHelp logo

uci's Introduction

UCI

NOTE:This version is not backwards compatible with 0.2.x series of releases.

UCI is a thin wrapper on a uci interface chess engine.

Installation

Make sure you have node.js installed. Then do:

$ npm install uci

Example

var Engine = require('uci');
var engine = new Engine('<path to engine executable>');
engine.runProcess().then(function () {
    console.log('Started');
    return engine.uciCommand();
}).then(function (idAndOptions) {
    console.log('Engine name - ' + idAndOptions.id.name);
    return engine.isReadyCommand();
}).then(function () {
    console.log('Ready');
    return engine.uciNewGameCommand();
}).then(function () {
    console.log('New game started');
    return engine.positionCommand('startpos', 'e2e4 e7e5');
}).then(function () {
    console.log('Starting position set');
	console.log('Starting analysis');
    return engine.goInfiniteCommand(function infoHandler(info) {
        console.log(info);
    });
}).delay(2000).then(function () {
    console.log('Stopping analysis');
    return engine.stopCommand();
}).then(function (bestmove) {
    console.log('Bestmove: ');
    console.log(bestmove);
    return engine.quitCommand();
}).then(function () {
    console.log('Stopped');
}).fail(function (error) {
    console.log(error);
    process.exit();
}).done();

API

See here for API reference.

Contributing

Fork, pick an issue to fix from issues or add a missing feature and send a pull request.

License

UCI is released under the MIT License. See the bundled LICENSE file for details.

uci's People

Contributors

efirvida avatar imor avatar jaxony avatar kohlhofer avatar tannerrogalsky avatar valera-rozuvan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uci's Issues

Not able to install uci , error VCBUILD : error : project file

Not able to install uci, getting the following error. Why can't we have the binaries directly ?

C:\shakti\nodejs\eclipse\Enide-Studio-05-kepler-win64\ws\uci>npm install uci
npm http GET https://registry.npmjs.org/uci
npm http 200 https://registry.npmjs.org/uci
npm http GET https://registry.npmjs.org/uci/-/uci-0.2.16.tgz
npm http 200 https://registry.npmjs.org/uci/-/uci-0.2.16.tgz
npm http GET https://registry.npmjs.org/chess.js
npm http GET https://registry.npmjs.org/q
npm http GET https://registry.npmjs.org/polyglot-chess
npm http GET https://registry.npmjs.org/string
npm http GET https://registry.npmjs.org/is-running
npm http 200 https://registry.npmjs.org/polyglot-chess
npm http GET https://registry.npmjs.org/polyglot-chess/-/polyglot-chess-0.1.6.tgz
npm http 200 https://registry.npmjs.org/chess.js
npm http GET https://registry.npmjs.org/chess.js/-/chess.js-0.1.0.tgz
npm http 200 https://registry.npmjs.org/chess.js/-/chess.js-0.1.0.tgz
npm http 200 https://registry.npmjs.org/polyglot-chess/-/polyglot-chess-0.1.6.tgz
npm http 200 https://registry.npmjs.org/is-running
npm http GET https://registry.npmjs.org/is-running/-/is-running-1.0.5.tgz
npm http 200 https://registry.npmjs.org/string
npm http GET https://registry.npmjs.org/string/-/string-1.7.0.tgz
npm http 200 https://registry.npmjs.org/string/-/string-1.7.0.tgz
npm http 200 https://registry.npmjs.org/is-running/-/is-running-1.0.5.tgz
npm http 200 https://registry.npmjs.org/q
npm http GET https://registry.npmjs.org/q/-/q-0.9.7.tgz
npm http 200 https://registry.npmjs.org/q/-/q-0.9.7.tgz

[email protected] install C:\shakti\nodejs\node_modules\uci\node_modules\polyglot-chess
node-gyp rebuild

C:\shakti\nodejs\node_modules\uci\node_modules\polyglot-chess>node "C:\shakti\nodejs\node_modules\npm\bin\node-gyp-bin....\node_modules\node-gyp\bin\node-gyp
.js" rebuild
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
VCBUILD : error : project file 'C:\shakti\nodejs\node_modules\uci\node_modules\polyglot-chess\build\polyglot.vcproj' was not found or not a valid project file.
[C:\shakti\nodejs\node_modules\uci\node_modules\polyglot-chess\build\binding.sln]
gyp ERR! build error
gyp ERR! stack Error: C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\shakti\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:267:23)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:\shakti\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:\shakti\nodejs\node_modules\uci\node_modules\polyglot-chess
gyp ERR! node -v v0.10.25
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok
npm ERR! [email protected] install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the polyglot-chess package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls polyglot-chess
npm ERR! There is likely additional logging output above.

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\shakti\nodejs\node.exe" "C:\shakti\nodejs\node_modules\npm\bin\npm-cli.js" "install" "uci"
npm ERR! cwd C:\shakti\nodejs\eclipse\Enide-Studio-05-kepler-win64\ws\uci
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.24
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! C:\shakti\nodejs\eclipse\Enide-Studio-05-kepler-win64\ws\uci\npm-debug.log
npm ERR! not ok code 0

npm test ERROR

$ npm install
$ npm test
 > [email protected] test E:\ProjectAll\npm\uci-gh-pages
 > mocha
   Engine
    contructor
      √ throws when no engine path is provided
      √ does not throw on bad engine path
    runProcess
      √ throws when tries to launch non existent path
      √ throws timeout error if executable does not start within allowed timeout period (1112ms)
      1) does not throw if executable launched OK

  4 passing (2s)
  1 failing

  1) Engine
       runProcess
         does not throw if executable launched OK:
     AssertionError: expected promise not to be rejected but it was rejected with 'Error: timeout while starting process'
npm ERR! Test failed.  See above for more details.

adding engine strength

Hi, it would be great if you can add an function which sets the strength of the engine. If I'm not wrong, it can be done by the parameter "UCI_LimitStrength".
When stockfish or other engines play on there maximum power I have no chance to win a game.

Thank you.

more functional

Seems that the code is somewhere repeating itself.
How about a bit refactor it in functional style some places, on the way performing TODOs?
I can do this, if you appreciate.

What is this?

What is this? What does it do? Can I get examples?

I am trying to figure out how to get stockfish working on my webpage so I can play a game against stockfish. Will this help?

Question about feature feasability

I am asking here, because perhaps, the development being fresh in your minds, you would have some sort of idea of an answer.

How much commitment or work would be required to make a symmetric UCI interface (engine both sides possible), which would display each move candidates on some graphic board display module capable of move list I/O (some hybrid of chess-ground and explorer in lichess, without the database),
and which would allow human interaction at each move, either choosing a move line candidate of another move that the human wish to explore?

Any existing software elements that could be part of this? sorry if this is not appropriate, I thought it would.

error on final move of the engine

I'm using the library with stockfish 6 and when the engine give his final best move the library raise an error "Error: Invalid format of bestmove. Expected "bestmove ".

var moveRegex = /bestmove (.*?) /g;
didn't match the final move expression

Add depth and time bound (movetime) Go commands

I used this module recently and it worked very nicely (although understanding promises was a bit of a learning curve for me), so thanks for uploading this project.
In go infinite + stop approach, stockfish sometimes outputs a "bestmove" without "ponder" (especially for low time values with high multipv settings) as a result, the regular expression fails, why not change it to simple string split?
In my testing I found that go-infinite + stop approach is somewhat less stable than the go movetime one. The later lets engine overshoot few milliseconds to but gives correct output all the time.

//---------------------------------------------------------------------
Engine.prototype.depthLimitedGoCommand = function (infoHandler,
                                                   depth) {
    var self = this;
    var deferred = Q.defer();

    var engineStdoutListener = function (data) {
        var lines = data.toString().split(endOfLineRegExp);
        var last_multipv = "";
        for (var i = 0; i < lines.length; i++) {
            var stringifiedLine = S(lines[i]);
            if (stringifiedLine.includes('multipv') && infoHandler) {
                last_multipv = lines[i];
                infoHandler(lines[i]);
            } else if (stringifiedLine.startsWith('bestmove')) {
                self.engineProcess.stdout.removeListener('data', engineStdoutListener);
                var bestmove_components = stringifiedLine.split(" ");
                if (bestmove_components.length > 1) {
                    //deferred.resolve(utilities.convertToMoveObject(bestmove_components[1]));
                    deferred.resolve(last_multipv);
                } else {
                    throw new Error('Invalid format of bestmove. Expected "bestmove <move>". Returned "' + lines[i] + '"');
                }
            }
        }
    };

    this.engineProcess.stdout.on('data', engineStdoutListener);
    var commandString = 'go depth ' + depth;
    this.engineProcess.stdin.write(commandString + endOfLine);
    return deferred.promise;
};

Engine.prototype.timeBoundGoCommand = function (infoHandler,
                                                t) {
    var self = this;
    var deferred = Q.defer();

    var engineStdoutListener = function (data) {
        var lines = data.toString().split(endOfLineRegExp);
        var last_multipv = "";
        for (var i = 0; i < lines.length; i++) {
            var stringifiedLine = S(lines[i]);
            if (stringifiedLine.includes('multipv') && infoHandler) {
                last_multipv = lines[i];
                infoHandler(lines[i]);
            } else if (stringifiedLine.startsWith('bestmove')) {
                self.engineProcess.stdout.removeListener('data', engineStdoutListener);
                var bestmove_components = stringifiedLine.split(" ");
                if (bestmove_components.length > 1) {
                    //deferred.resolve(utilities.convertToMoveObject(bestmove_components[1]));
                    deferred.resolve(last_multipv);
                } else {
                    throw new Error('Invalid format of bestmove. Expected "bestmove <move>". Returned "' + lines[i] + '"');
                }
            }
        }
    };

    this.engineProcess.stdout.on('data', engineStdoutListener);
    var commandString = 'go movetime ' + t;
    this.engineProcess.stdin.write(commandString + endOfLine);
    return deferred.promise;
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.