Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add depth and time bound (movetime) Go commands #24

Open
abhijeetnvaidya opened this issue Mar 10, 2016 · 2 comments
Open

Add depth and time bound (movetime) Go commands #24

abhijeetnvaidya opened this issue Mar 10, 2016 · 2 comments

Comments

@abhijeetnvaidya
Copy link

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;
};
@imor
Copy link
Owner

imor commented Mar 11, 2016

@abhijeetnvaidya Glad that you liked the library 👍 . I don't fully understand which part of the code fails (right now my guess is line 278). Can you please post your code and stockfish version with which you saw this behavior. This info will help me in fixing the bug. Also please post the full exception trace.

@valanchik
Copy link

valanchik commented Jun 20, 2016

Glad that you liked the library 👍 . I don't fully understand which part of the code fails (right now my guess is line 278). Can you please post your code and stockfish version with which you saw this behavior. This info will help me in fixing the bug. Also please post the full exception trace.

make like this:
...).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(5000).then(function () {... with delay 5 sec

and append console.log like this in main.js:
...var engineStdoutListener = function (data) { console.log('engineStdoutListener',data.toString()); var lines = data.toString().split(endOfLineRegExp);...

im using engine:
new Engine(__dirname+'/engines/stockfish_7_x64');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants