-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
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;
};Metadata
Metadata
Assignees
Labels
No labels