Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gtp2ogs

Package Overview
Dependencies
Maintainers
2
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gtp2ogs - npm Package Compare versions

Comparing version 7.0.0 to 7.1.0-beta.1

dist/Bot.js.map

301

dist/Bot.js

@@ -16,3 +16,3 @@ "use strict";

class Bot {
constructor(conn, game, cmd) {
constructor(conn, game, cmd, is_resign_bot = false) {
this.conn = conn;

@@ -23,2 +23,3 @@ this.game = game;

this.command_error_callbacks = [];
this.is_resign_bot = is_resign_bot;
this.firstmove = true;

@@ -100,5 +101,5 @@ this.ignore = false; // Ignore output from bot ?

const cb = this.command_callbacks.shift();
this.command_error_callbacks.shift();
this.command_error_callbacks.shift(); // discard;
if (cb) {
cb(line.substr(1).trim());
cb(line.substring(1).trim());
}

@@ -113,17 +114,16 @@ }

this.failed = true;
this.command_callbacks.shift();
this.command_callbacks.shift(); // discard;
const eb = this.command_error_callbacks.shift();
if (eb) {
eb(line.substr(1).trim());
eb(line.substring(1).trim());
}
}
else {
this.log("Unexpected output: ", line);
this.error("Unexpected output: ", line);
this.failed = true;
this.command_callbacks.shift();
this.command_callbacks.shift(); // discard;
const eb = this.command_error_callbacks.shift();
if (eb) {
eb();
eb(line.trim());
}
//throw new Error(`Unexpected output: ${line}`);
}

@@ -133,9 +133,15 @@ }

this.proc.on("exit", (code) => {
if (config_1.config.DEBUG) {
this.log("Bot exited");
const unexpected = !this.dead;
if (unexpected) {
if (code) {
this.log("Bot exited", code);
}
else {
this.log("Bot exited");
}
}
this.command_callbacks.shift();
this.command_callbacks.shift(); // discard;
this.dead = true;
const eb = this.command_error_callbacks.shift();
if (eb) {
if (unexpected && eb) {
eb(code);

@@ -145,6 +151,4 @@ }

this.proc.stdin.on("error", (code) => {
if (config_1.config.DEBUG) {
this.log("Bot stdin write error");
}
this.command_callbacks.shift();
this.error("Bot stdin write error", code);
this.command_callbacks.shift(); // discard;
this.dead = true;

@@ -167,9 +171,18 @@ this.failed = true;

log(...arr) {
trace_1.trace.log.apply(null, [`[${this.pid()}]`, ...arr]);
trace_1.trace.log.apply(null, [
`[${this.is_resign_bot ? "resign bot " : ""}${this.pid()}]`,
...arr,
]);
}
error(...arr) {
trace_1.trace.error.apply(null, [`[${this.pid()}]`, ...arr]);
trace_1.trace.error.apply(null, [
`[${this.is_resign_bot ? "resign bot " : ""}${this.pid()}]`,
...arr,
]);
}
verbose(...arr) {
trace_1.trace.verbose.apply(null, [`[${this.pid()}]`, ...arr]);
trace_1.trace.verbose.apply(null, [
`[${this.is_resign_bot ? "resign bot " : ""}${this.pid()}]`,
...arr,
]);
}

@@ -256,5 +269,5 @@ loadClock(state) {

}
this.command(`kgs-time_settings byoyomi ${state.time_control.main_time} ${state.time_control.period_time} ${state.time_control.periods}`);
this.command(`time_left black ${Math.floor(Math.max(black_timeleft, 0))} ${black_time > 0 ? "0" : black_periods}`);
this.command(`time_left white ${Math.floor(Math.max(white_timeleft, 0))} ${white_time > 0 ? "0" : white_periods}`);
void this.command(`kgs-time_settings byoyomi ${state.time_control.main_time} ${state.time_control.period_time} ${state.time_control.periods}`);
void this.command(`time_left black ${Math.floor(Math.max(black_timeleft, 0))} ${black_time > 0 ? "0" : black_periods}`);
void this.command(`time_left white ${Math.floor(Math.max(white_timeleft, 0))} ${white_time > 0 ? "0" : white_periods}`);
}

@@ -293,16 +306,16 @@ else {

}
this.command(`time_settings ${state.time_control.main_time +
void this.command(`time_settings ${state.time_control.main_time +
(state.time_control.periods - 1) * state.time_control.period_time} ${state.time_control.period_time} 1`);
// If we're in the last period, tell the bot. Otherwise pretend we're in main time.
if (black_timeleft <= state.clock.black_time.period_time) {
this.command(`time_left black ${Math.floor(Math.max(black_timeleft, 0))} 1`);
void this.command(`time_left black ${Math.floor(Math.max(black_timeleft, 0))} 1`);
}
else {
this.command(`time_left black ${Math.floor(black_timeleft - state.clock.black_time.period_time)} 0`);
void this.command(`time_left black ${Math.floor(black_timeleft - state.clock.black_time.period_time)} 0`);
}
if (white_timeleft <= state.clock.white_time.period_time) {
this.command(`time_left white ${Math.floor(Math.max(white_timeleft, 0))} 1`);
void this.command(`time_left white ${Math.floor(Math.max(white_timeleft, 0))} 1`);
}
else {
this.command(`time_left white ${Math.floor(white_timeleft - state.clock.white_time.period_time)} 0`);
void this.command(`time_left white ${Math.floor(white_timeleft - state.clock.white_time.period_time)} 0`);
}

@@ -327,9 +340,9 @@ }

if (this.kgstime) {
this.command(`kgs-time_settings canadian ${state.time_control.main_time} ${state.time_control.period_time} ${state.time_control.stones_per_period}`);
void this.command(`kgs-time_settings canadian ${state.time_control.main_time} ${state.time_control.period_time} ${state.time_control.stones_per_period}`);
}
else {
this.command(`time_settings ${state.time_control.main_time} ${state.time_control.period_time} ${state.time_control.stones_per_period}`);
void this.command(`time_settings ${state.time_control.main_time} ${state.time_control.period_time} ${state.time_control.stones_per_period}`);
}
this.command(`time_left black ${Math.floor(Math.max(black_timeleft, 0))} ${black_stones}`);
this.command(`time_left white ${Math.floor(Math.max(white_timeleft, 0))} ${white_stones}`);
void this.command(`time_left black ${Math.floor(Math.max(black_timeleft, 0))} ${black_stones}`);
void this.command(`time_left white ${Math.floor(Math.max(white_timeleft, 0))} ${white_stones}`);
}

@@ -340,5 +353,5 @@ else if (state.time_control.system === "fischer") {

const white_timeleft = state.clock.white_time.thinking_time - white_offset;
this.command(`kata-time_settings fischer-capped ${state.time_control.initial_time} ${state.time_control.time_increment} ${state.time_control.max_time} -1`);
this.command(`time_left black ${Math.floor(Math.max(black_timeleft, 0))} 0`);
this.command(`time_left white ${Math.floor(Math.max(white_timeleft, 0))} 0`);
void this.command(`kata-time_settings fischer-capped ${state.time_control.initial_time} ${state.time_control.time_increment} ${state.time_control.max_time} -1`);
void this.command(`time_left black ${Math.floor(Math.max(black_timeleft, 0))} 0`);
void this.command(`time_left white ${Math.floor(Math.max(white_timeleft, 0))} 0`);
}

@@ -360,6 +373,6 @@ else {

if (this.kgstime) {
this.command(`kgs-time_settings canadian ${state.time_control.initial_time - state.time_control.time_increment} ${state.time_control.time_increment} 1`);
void this.command(`kgs-time_settings canadian ${state.time_control.initial_time - state.time_control.time_increment} ${state.time_control.time_increment} 1`);
}
else {
this.command(`time_settings ${state.time_control.initial_time - state.time_control.time_increment} ${state.time_control.time_increment} 1`);
void this.command(`time_settings ${state.time_control.initial_time - state.time_control.time_increment} ${state.time_control.time_increment} 1`);
}

@@ -378,4 +391,4 @@ if (black_timeleft <= 0) {

*/
this.command(`time_left black ${Math.floor(Math.max(black_timeleft, 0))} ${black_periods}`);
this.command(`time_left white ${Math.floor(Math.max(white_timeleft, 0))} ${white_periods}`);
void this.command(`time_left black ${Math.floor(Math.max(black_timeleft, 0))} ${black_periods}`);
void this.command(`time_left white ${Math.floor(Math.max(white_timeleft, 0))} ${white_periods}`);
}

@@ -391,5 +404,5 @@ }

const white_timeleft = state.time_control.per_move - white_offset;
this.command(`time_settings 0 ${state.time_control.per_move} 1`);
this.command(`time_left black ${Math.floor(Math.max(black_timeleft, 0))} 1`);
this.command(`time_left white ${Math.floor(Math.max(white_timeleft, 0))} 1`);
void this.command(`time_settings 0 ${state.time_control.per_move} 1`);
void this.command(`time_left black ${Math.floor(Math.max(black_timeleft, 0))} 1`);
void this.command(`time_left white ${Math.floor(Math.max(white_timeleft, 0))} 1`);
}

@@ -399,5 +412,5 @@ else if (state.time_control.system === "absolute") {

const white_timeleft = state.clock.white_time.thinking_time - white_offset;
this.command(`time_settings ${state.time_control.total_time} 0 0`);
this.command(`time_left black ${Math.floor(Math.max(black_timeleft, 0))} 0`);
this.command(`time_left white ${Math.floor(Math.max(white_timeleft, 0))} 0`);
void this.command(`time_settings ${state.time_control.total_time} 0 0`);
void this.command(`time_left black ${Math.floor(Math.max(black_timeleft, 0))} 0`);
void this.command(`time_left white ${Math.floor(Math.max(white_timeleft, 0))} 0`);
}

@@ -416,39 +429,26 @@ /* OGS doesn't actually send 'none' time control type

}
loadState(state, cb, eb) {
async loadState(state) {
if (this.dead) {
if (config_1.config.DEBUG) {
this.log("Attempting to load dead bot");
}
this.failed = true;
if (eb) {
eb();
}
return;
this.error("Attempted to load state to a dead bot");
throw new Error("Attempting to load dead bot");
}
this.command("list_commands", (commands) => {
this.kgstime = commands.includes("kgs-time_settings");
this.katatime = commands.includes("kata-list_time_settings");
if (this.katatime) {
this.command("kata-list_time_settings", (kataTimeSettings) => {
this.katafischer = kataTimeSettings.includes("fischer-capped");
this.loadState2(state, cb, eb);
}, eb);
}
else {
this.katafischer = false;
this.loadState2(state, cb, eb);
}
}, eb);
}
loadState2(state, cb, eb) {
const commands = await this.command("list_commands");
this.kgstime = commands.includes("kgs-time_settings");
this.katatime = commands.includes("kata-list_time_settings");
if (this.katatime) {
const kataTimeSettings = await this.command("kata-list_time_settings");
this.katafischer = kataTimeSettings.includes("fischer-capped");
}
else {
this.katafischer = false;
}
if (state.width === state.height) {
this.command(`boardsize ${state.width}`, () => { }, eb);
await this.command(`boardsize ${state.width}`);
}
else {
this.command(`boardsize ${state.width} ${state.height}`, () => { }, eb);
await this.command(`boardsize ${state.width} ${state.height}`);
}
this.command("clear_board", () => { }, eb);
this.command(`komi ${state.komi}`, () => { }, eb);
//this.log(state);
//this.loadClock(state);
await this.command("clear_board");
await this.command(`komi ${state.komi}`);
let have_initial_state = false;

@@ -460,6 +460,6 @@ if (state.initial_state) {

for (let i = 0; i < black.length; ++i) {
this.command(`play black ${(0, gtp_1.move2gtpvertex)(black[i], state.width, state.height)}`, () => { }, eb);
await this.command(`play black ${(0, gtp_1.move2gtpvertex)(black[i], state.width, state.height)}`);
}
for (let i = 0; i < white.length; ++i) {
this.command(`play white ${(0, gtp_1.move2gtpvertex)(white[i], state.width, state.height)}`, () => { }, eb);
await this.command(`play white ${(0, gtp_1.move2gtpvertex)(white[i], state.width, state.height)}`);
}

@@ -478,3 +478,3 @@ }

if (handicap_moves.length === state.handicap) {
this.sendHandicapMoves(handicap_moves, state.width, state.height);
void this.sendHandicapMoves(handicap_moves, state.width, state.height);
}

@@ -486,3 +486,3 @@ else {

else {
this.command(`play ${color} ${(0, gtp_1.move2gtpvertex)(move, state.width, state.height)}`);
await this.command(`play ${color} ${(0, gtp_1.move2gtpvertex)(move, state.width, state.height)}`);
}

@@ -492,57 +492,52 @@ color = color === "black" ? "white" : "black";

if (config_1.config.showboard) {
this.command("showboard", cb, eb);
return await this.command("showboard");
}
else {
cb();
}
return "";
}
command(str, cb, eb, final_command) {
if (this.dead) {
command(str, final_command) {
return new Promise((resolve, reject) => {
if (this.dead) {
this.error("Attempting to send a command to dead bot:", str);
this.failed = true;
reject(`Attempting to send a command to dead bot: ${str}`);
return;
}
this.command_callbacks.push(resolve);
this.command_error_callbacks.push(reject);
if (config_1.config.DEBUG) {
this.log("Attempting to send a command to dead bot:", str);
this.log(">>>", str);
}
this.failed = true;
if (eb) {
eb();
}
return;
}
this.command_callbacks.push(cb);
this.command_error_callbacks.push(eb);
if (config_1.config.DEBUG) {
this.log(">>>", str);
}
try {
if (config_1.config.json) {
if (!this.json_initialized) {
this.proc.stdin.write(`{"gtp_commands": [`);
this.json_initialized = true;
try {
if (config_1.config.json) {
if (!this.json_initialized) {
this.proc.stdin.write(`{"gtp_commands": [`);
this.json_initialized = true;
}
else {
this.proc.stdin.write(",");
}
this.proc.stdin.write(JSON.stringify(str));
if (final_command) {
this.proc.stdin.write("]}");
this.proc.stdin.end();
}
}
else {
this.proc.stdin.write(",");
this.proc.stdin.write(`${str}\r\n`);
}
this.proc.stdin.write(JSON.stringify(str));
if (final_command) {
this.proc.stdin.write("]}");
this.proc.stdin.end();
}
}
else {
this.proc.stdin.write(`${str}\r\n`);
catch (e) {
// I think this does not normally happen, the exception will usually be raised in the async write handler
// and delivered through an 'error' event.
//
this.error("Failed to send command: ", str);
this.error(e);
this.dead = true;
this.failed = true;
// Already calling the callback!
this.command_error_callbacks.shift();
reject(e);
return;
}
}
catch (e) {
// I think this does not normally happen, the exception will usually be raised in the async write handler
// and delivered through an 'error' event.
//
this.log("Failed to send command: ", str);
this.log(e);
this.dead = true;
this.failed = true;
// Already calling the callback!
this.command_error_callbacks.shift();
if (eb) {
eb(e);
}
}
});
}

@@ -553,3 +548,3 @@ // For commands like genmove, place_free_handicap ... :

//
getMoves(cmd, state, cb, eb) {
async getMoves(cmd, state) {
// Do this here so we only do it once, plus if there is a long delay between clock message and move message, we'll

@@ -563,26 +558,24 @@ // subtract that missing time from what we tell the bot.

this.firstmove = false;
this.command(cmd, (line) => {
line = typeof line === "string" ? line.toLowerCase() : null;
const parts = line.split(/ +/);
const moves = [];
for (let i = 0; i < parts.length; i++) {
const move = parts[i];
let resign = move === "resign";
const pass = move === "pass";
let x = -1;
let y = -1;
if (!resign && !pass) {
if (move && move[0]) {
x = (0, gtp_1.gtpchar2num)(move[0]);
y = state.height - parseInt(move.substr(1));
}
else {
this.log(`${cmd} failed, resigning`);
resign = true;
}
const line = await this.command(cmd, true /* final command */);
const parts = line.toLowerCase().split(/ +/);
const moves = [];
for (let i = 0; i < parts.length; i++) {
const move = parts[i];
let resign = move === "resign";
const pass = move === "pass";
let x = -1;
let y = -1;
if (!resign && !pass) {
if (move && move[0]) {
x = (0, gtp_1.gtpchar2num)(move[0]);
y = state.height - parseInt(move.substring(1));
}
moves.push({ x: x, y: y, text: move, resign: resign, pass: pass });
else {
this.log(`${cmd} failed, resigning`);
resign = true;
}
}
cb(moves);
}, eb, true /* final command */);
moves.push({ x, y, text: move, resign, pass });
}
return moves;
}

@@ -593,3 +586,3 @@ kill() {

// "quit" needs to be sent before we toggle this.dead since command() checks the status of this.dead
this.command("quit");
void this.command("quit");
this.dead = true;

@@ -607,9 +600,9 @@ if (this.proc) {

}
sendMove(move, width, height, color) {
async sendMove(move, width, height, color) {
if (config_1.config.DEBUG) {
this.log("Calling sendMove with", (0, gtp_1.move2gtpvertex)(move, width, height));
}
this.command(`play ${color} ${(0, gtp_1.move2gtpvertex)(move, width, height)}`);
await this.command(`play ${color} ${(0, gtp_1.move2gtpvertex)(move, width, height)}`);
}
sendHandicapMoves(moves, width, height) {
async sendHandicapMoves(moves, width, height) {
let cmd = "set_free_handicap";

@@ -619,3 +612,3 @@ for (let i = 0; i < moves.length; i++) {

}
this.command(cmd);
await this.command(cmd);
}

@@ -627,1 +620,3 @@ // Called on game over, in case you need something special.

exports.Bot = Bot;
//# sourceMappingURL=../dist/Bot.js.map

@@ -15,3 +15,3 @@ "use strict";

const debugStatus = argv.debug ? "DEBUG: ON\n" : "";
trace_1.trace.log(`\ngtp2ogs version 6.0.1\n--------------------\n- For changelog or latest devel updates, please visit https://github.com/online-go/gtp2ogs/tree/devel\n${debugStatus}`);
trace_1.trace.log(`\ngtp2ogs version ${process.env.npm_package_version || "development"}\n--------------------\n- For changelog or latest devel updates, please visit https://github.com/online-go/gtp2ogs/tree/devel\n${debugStatus}`);
constants_2.config.min_move_time = argv.minMoveTime || 0;

@@ -57,2 +57,15 @@ // B - test unsupported argv

constants_2.config.bot_command = argv._;
if (argv.resignbot) {
/* Our full resign bot command needs to be encapsulated in qoutes as
* it's a shell command to run, this splits that command into an array
* like we normally expect for a bot command. Note while this does handle
* one level of qoutes, it doesn't handle qoute escaping or any other
* fancy stuff, so I appologize in advance if you bump into that.
* Here is the place to address that though if you need it.
*/
const cmd = argv.resignbot
.split(/'(.*?)'|"(.*?)"|\s/)
.filter((x) => x !== undefined && x !== "");
constants_2.config.resign_bot_command = cmd;
}
// 2) specific ranked/unranked options exports

@@ -328,1 +341,3 @@ exportMinMaxRanks(argv);

}
//# sourceMappingURL=../dist/config.js.map

@@ -1069,1 +1069,3 @@ "use strict";

}
//# sourceMappingURL=../dist/Connection.js.map

@@ -107,1 +107,3 @@ "use strict";

}
//# sourceMappingURL=../dist/constants.js.map

@@ -21,3 +21,4 @@ "use strict";

this.connected = true;
this.bot = null;
this.bot = undefined;
this.resign_bot = undefined;
this.bot_failures = 0;

@@ -51,3 +52,3 @@ this.my_color = null;

this.state = gamedata;
this.gameOver();
void this.gameOver();
}

@@ -126,3 +127,3 @@ return; // ignore -- it's either handled by gameOver or we already handled it before.

if (!this.bot || !this.processing) {
this.makeMove(this.state.moves.length);
void this.makeMove(this.state.moves.length);
}

@@ -162,3 +163,2 @@ }

}
//this.log("Clock: ", JSON.stringify(clock));
if (this.state) {

@@ -172,6 +172,2 @@ this.state.clock = clock;

}
// Bot only needs updated clock info right before a genmove, and extra communcation would interfere with Leela pondering.
//if (this.bot) {
// this.bot.loadClock(this.state);
//}
});

@@ -240,3 +236,3 @@ this.socket.on(`game/${game_id}/phase`, (phase) => {

//
this.makeMove(this.state.moves.length);
void this.makeMove(this.state.moves.length);
}

@@ -246,6 +242,7 @@ else {

if (this.bot) {
this.bot.sendMove((0, gtp_1.decodeMoves)(move.move, this.state.width, this.state.height)[0], this.state.width, this.state.height, this.my_color === "black" ? "white" : "black");
void this.bot.sendMove((0, gtp_1.decodeMoves)(move.move, this.state.width, this.state.height)[0], this.state.width, this.state.height, this.my_color === "black" ? "white" : "black");
void this.resign_bot.sendMove((0, gtp_1.decodeMoves)(move.move, this.state.width, this.state.height)[0], this.state.width, this.state.height, this.my_color === "black" ? "white" : "black");
}
if (config.DEBUG) {
this.log("Waiting for opponent to finish", this.state.handicap - this.state.moves.length, "more handicap moves");
this.verbose("Waiting for opponent to finish", this.state.handicap - this.state.moves.length, "more handicap moves");
}

@@ -263,3 +260,4 @@ if (this.state.moves.length === 1) {

if (this.bot) {
this.bot.sendMove((0, gtp_1.decodeMoves)(move.move, this.state.width, this.state.height)[0], this.state.width, this.state.height, this.my_color === "black" ? "white" : "black");
void this.bot.sendMove((0, gtp_1.decodeMoves)(move.move, this.state.width, this.state.height)[0], this.state.width, this.state.height, this.my_color === "black" ? "white" : "black");
void this.resign_bot.sendMove((0, gtp_1.decodeMoves)(move.move, this.state.width, this.state.height)[0], this.state.width, this.state.height, this.my_color === "black" ? "white" : "black");
}

@@ -272,3 +270,3 @@ if (config.corrqueue &&

else {
this.makeMove(this.state.moves.length);
void this.makeMove(this.state.moves.length);
}

@@ -304,7 +302,17 @@ //this.makeMove(this.state.moves.length);

this.bot.kill();
this.bot = null;
this.bot = undefined;
}
if (this.resign_bot) {
if (this.resign_bot.failed) {
this.resign_bot_failures++;
if (config.DEBUG) {
this.log(`Observed ${this.resign_bot_failures} resign_bot failures`);
}
}
this.resign_bot.kill();
this.resign_bot = undefined;
}
}
// Start the bot.
ensureBotStarted(cb, eb) {
async ensureBotStarted() {
if (this.bot && this.bot.dead) {

@@ -314,3 +322,2 @@ this.ensureBotKilled();

if (this.bot) {
cb();
return;

@@ -325,16 +332,20 @@ }

}));
if (eb) {
eb();
}
return;
throw new Error("Bot has crashed too many times, resigning game");
}
this.bot = new Bot_1.Bot(this.conn, this, config.bot_command);
this.log(`Starting new bot process [${this.bot.pid()}]`);
this.log("State loading for new bot");
this.bot.loadState(this.state, () => {
this.bot.log(`[game ${this.game_id}] Starting up bot: ${config.bot_command.join(" ")}`);
this.bot.log(`[game ${this.game_id}] Loading state`);
await this.bot.loadState(this.state);
if (config.DEBUG) {
this.bot.log(`[game ${this.game_id}] State loaded successfully`);
}
if (config.resign_bot_command) {
this.resign_bot = new Bot_1.Bot(this.conn, this, config.resign_bot_command, true /* is resign bot */);
this.resign_bot.log(`[game ${this.game_id}] Starting up resign bot: ${config.resign_bot_command.join(" ")}`);
this.resign_bot.log(`[game ${this.game_id}] Loading state`);
await this.resign_bot.loadState(this.state);
if (config.DEBUG) {
this.log("State loaded for new bot");
this.resign_bot.log(`[game ${this.game_id}] State loaded successfully`);
}
cb();
}, eb);
}
}

@@ -352,3 +363,3 @@ checkBotPersists() {

//
getBotMoves(cmd, cb, eb) {
async getBotMoves(cmd) {
++Game.moves_processing;

@@ -367,30 +378,31 @@ this.processing = true;

};
let failed = false;
const botError = (e) => {
if (failed) {
return;
try {
await this.ensureBotStarted();
if (config.DEBUG) {
this.bot.log("Generating move for game", this.game_id);
}
failed = true;
this.log(cmd);
const [our_moves, resign_moves] = await Promise.all([
this.bot.getMoves(cmd, this.state),
this.resign_bot?.getMoves(cmd, this.state),
]);
this.verbose(`Our moves: ${JSON.stringify(our_moves)} Resign bot: ${JSON.stringify(resign_moves)}`);
const resign = resign_moves && resign_moves.length > 0 && resign_moves[0].resign;
if (resign) {
this.log("Our resign bot has indicated we should resign, so we are resigning");
}
doneProcessing();
if (!this.checkBotPersists()) {
this.ensureBotKilled();
}
return resign ? resign_moves : our_moves;
}
catch (e) {
doneProcessing();
this.ensureBotKilled();
if (eb) {
eb(e);
}
trace_1.trace.error(e);
this.log("Failed to start the bot, can not make a move, trying to restart");
this.sendChat("Failed to start the bot, can not make a move, trying to restart"); // we notify user of this in ingame chat
};
this.ensureBotStarted(() => this.getBotMoves2(cmd, cb, doneProcessing, botError), botError);
}
getBotMoves2(cmd, cb, doneProcessing, botError) {
if (config.DEBUG) {
this.bot.log("Generating move for game", this.game_id);
throw e;
}
this.log(cmd);
this.bot.getMoves(cmd, this.state, (moves) => {
doneProcessing();
cb(moves);
if (!this.checkBotPersists()) {
this.ensureBotKilled();
}
}, botError);
}

@@ -433,3 +445,3 @@ scheduleRetry() {

//
makeMove(move_number) {
async makeMove(move_number) {
if (config.DEBUG && this.state) {

@@ -460,3 +472,4 @@ this.log("makeMove", move_number, "is", this.state.moves.length, "!==", move_number, "?");

const move_start = Date.now();
const sendTheMove = (moves) => {
try {
const moves = await this.getBotMoves(`genmove ${this.my_color}`);
const move_end = Date.now();

@@ -473,4 +486,6 @@ const move_time = move_end - move_start;

}
};
this.getBotMoves(`genmove ${this.my_color}`, sendTheMove, this.scheduleRetry);
}
catch (e) {
this.scheduleRetry();
}
return;

@@ -489,3 +504,4 @@ }

// Get handicap stones from bot and return first one.
const storeMoves = (moves) => {
try {
const moves = await this.getBotMoves(`place_free_handicap ${this.state.handicap}`);
if (moves.length !== this.state.handicap) {

@@ -505,4 +521,6 @@ // Sanity check

this.uploadMove(this.handicap_moves.shift());
};
this.getBotMoves(`place_free_handicap ${this.state.handicap}`, storeMoves, this.scheduleRetry);
}
catch (e) {
this.scheduleRetry();
}
}

@@ -543,3 +561,3 @@ auth(obj) {

}
gameOver() {
async gameOver() {
if (config.farewell && this.state) {

@@ -556,19 +574,19 @@ this.sendChat(config.farewell, undefined, "discussion");

if (config.farewellscore && this.bot) {
const sendTheScore = (score) => {
if (score) {
this.log(`Bot thinks the score was ${score}`);
}
if (res !== "R" && res !== "Time" && res !== "Can") {
this.sendChat(`Final score was ${score} according to the bot.`, undefined, "discussion");
}
if (this.bot) {
// only kill the bot after it processed this
this.bot.gameOver();
this.ensureBotKilled();
}
};
this.bot.command("final_score", sendTheScore, null, true); // allow bot to process end of game
const score = await this.bot.command("final_score", true); // allow bot to process end of game
if (score) {
this.log(`Bot thinks the score was ${score}`);
}
if (res !== "R" && res !== "Time" && res !== "Can") {
this.sendChat(`Final score was ${score} according to the bot.`, undefined, "discussion");
}
if (this.bot) {
// only kill the bot after it processed this
this.bot.gameOver();
this.resign_bot?.gameOver();
this.ensureBotKilled();
}
}
else if (this.bot) {
this.bot.gameOver();
this.resign_bot?.gameOver();
this.ensureBotKilled();

@@ -606,2 +624,14 @@ }

}
verbose(...args) {
if (!config.DEBUG) {
return;
}
const moves = this.state && this.state.moves ? this.state.moves.length : 0;
const movestr = moves ? `Move ${moves}` : " ";
const arr = [`[Game ${this.game_id}] ${movestr} `];
for (let i = 0; i < args.length; ++i) {
arr.push(args[i]);
}
trace_1.trace.log.apply(null, arr);
}
sendChat(str, move_number, type = "discussion") {

@@ -613,3 +643,3 @@ if (!this.connected) {

game_id: this.game_id,
player_id: this.conn.user_id,
player_id: this.conn.bot_id,
body: str,

@@ -655,1 +685,3 @@ move_number: move_number,

Game.corr_moves_processing = 0;
//# sourceMappingURL=../dist/Game.js.map

@@ -14,2 +14,3 @@ "use strict";

.describe("apikey", "Specify the API key for the bot")
.describe("resignbot", "Specify an alternative bot command to run and consult for every move. If this bot at anypoint indicates that we should resign, we resign instead of playing our primary bot's move.")
.describe("minMoveTime", "Specify the minimum move time in milliseconds. Bots that move faster than this will have an artificial delay added before submitting the move to slow the game down.")

@@ -179,1 +180,3 @@ .describe("greeting", "Greeting message to appear in chat at first move (ex: Hello, have a nice game)")

exports.getArgv = getArgv;
//# sourceMappingURL=../dist/getArgv.js.map

@@ -11,1 +11,3 @@ "use strict";

exports.char2num = char2num;
//# sourceMappingURL=../../dist/gtp/char2num.js.map

@@ -95,1 +95,3 @@ "use strict";

}
//# sourceMappingURL=../../dist/gtp/decodeMoves.js.map

@@ -11,1 +11,3 @@ "use strict";

exports.gtpchar2num = gtpchar2num;
//# sourceMappingURL=../../dist/gtp/gtpchar2num.js.map

@@ -22,1 +22,3 @@ "use strict";

__exportStar(require("./num2char"), exports);
//# sourceMappingURL=../../dist/gtp/index.js.map

@@ -17,1 +17,3 @@ "use strict";

}
//# sourceMappingURL=../../dist/gtp/move2gtpvertex.js.map

@@ -11,1 +11,3 @@ "use strict";

exports.num2char = num2char;
//# sourceMappingURL=../../dist/gtp/num2char.js.map

@@ -15,5 +15,5 @@ #!/usr/bin/env node

const Connection_1 = require("./Connection");
process.on("uncaughtException", (er) => {
process.on("uncaughtException", (err) => {
console.trace("ERROR: Uncaught exception");
trace_1.trace.error(`ERROR: ${er.stack}`);
trace_1.trace.error(err);
if (!conn || !conn.socket) {

@@ -30,1 +30,3 @@ conn = getNewConnection();

}
//# sourceMappingURL=../dist/gtp2ogs.js.map

@@ -8,1 +8,3 @@ "use strict";

exports.getArgNamesGRU = getArgNamesGRU;
//# sourceMappingURL=../../dist/options/getArgNamesGRU.js.map

@@ -8,1 +8,3 @@ "use strict";

exports.getArgNamesUnderscoredGRU = getArgNamesUnderscoredGRU;
//# sourceMappingURL=../../dist/options/getArgNamesUnderscoredGRU.js.map

@@ -8,1 +8,3 @@ "use strict";

exports.getOptionName = getOptionName;
//# sourceMappingURL=../../dist/options/getOptionName.js.map

@@ -16,1 +16,3 @@ "use strict";

exports.getRankedUnranked = getRankedUnranked;
//# sourceMappingURL=../../dist/options/getRankedUnranked.js.map

@@ -13,1 +13,3 @@ "use strict";

exports.getRankedUnrankedUnderscored = getRankedUnrankedUnderscored;
//# sourceMappingURL=../../dist/options/getRankedUnrankedUnderscored.js.map

@@ -22,1 +22,3 @@ "use strict";

__exportStar(require("./getRankedUnrankedUnderscored"), exports);
//# sourceMappingURL=../../dist/options/index.js.map

@@ -171,1 +171,3 @@ "use strict";

exports.Pv = Pv;
//# sourceMappingURL=../dist/Pv.js.map

@@ -49,1 +49,3 @@ "use strict";

exports.trace = tracer.colorConsole(console_config);
//# sourceMappingURL=../dist/trace.js.map
{
"name": "gtp2ogs",
"version": "7.0.0",
"version": "7.1.0-beta.1",
"description": "Wrapper to allow Gnu Go Text Protocol speaking Go engines to connect to Online-Go.com and play games",

@@ -16,24 +16,24 @@ "files": [

"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/eslint-plugin-tslint": "^5.26.0",
"@typescript-eslint/parser": "^5.26.0",
"@types/node": "^16.11.6",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.5.0",
"@typescript-eslint/eslint-plugin": "^5.48.0",
"@typescript-eslint/eslint-plugin-tslint": "^5.48.0",
"@typescript-eslint/parser": "^5.48.0",
"@types/node": "^18.11.18",
"eslint": "^8.31.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsdoc": "^39.3.1",
"eslint-plugin-jsdoc": "^39.6.4",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react-hooks": "^4.5.0",
"eslint-plugin-unicorn": "^42.0.0",
"markdownlint": "^0.20.2",
"markdownlint-cli": "^0.22.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-unicorn": "^45.0.2",
"markdownlint": "^0.26.2",
"markdownlint-cli": "^0.32.2",
"mocha": "^10.0.0",
"gulp": "^4.0.2",
"gulp-eslint-new": "^1.4.4",
"gulp-sourcemaps": "^3.0.0",
"gulp-typescript": "^6.0.0-alpha.1",
"nyc": "^15.0.1",
"prettier": "2.6.2",
"prettier-eslint": "^15.0.0",
"typescript": "^4.7.2",
"prettier": "2.8.2",
"prettier-eslint": "^15.0.1",
"typescript": "^4.9.4",
"sinon": "^9.0.2"

@@ -40,0 +40,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc