Skip to content

Commit

Permalink
Update to support rapid time controls
Browse files Browse the repository at this point in the history
  • Loading branch information
anoek committed Dec 9, 2024
1 parent 85a8b43 commit b6dd13b
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 32 deletions.
29 changes: 27 additions & 2 deletions example_config.json5
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,35 @@

/**
* Allowed blitz times for the bot. Blitz is disabled by default, but you
* can enable it by providing accetpable time settings.
* can enable it by providing acceptable time settings.
*
* @default null
*/
// allowed_blitz_settings: null,

/** Allowed rapid game times for bot. */
/*
allowed_rapid_settings: {
simple: {
per_move_time_range: [5, 30],
},
byoyomi: {
main_time_range: [0, 3600],
period_time_range: [5, 30],
periods_range: [1, 10],
},
fischer: {
initial_time_range: [5, 600],
max_time_range: [5, 7200],
time_increment_range: [3, 30],
},
concurrent_games: 3,
},
*/

/** Allowed live game times for bot. */
/*
allowed_live_settings: {
Expand All @@ -239,7 +262,8 @@
},
fischer: {
max_time_range: [30, 600],
initial_time_range: [10, 3600],
max_time_range: [5, 7200],
time_increment_range: [10, 300],
},
Expand All @@ -261,6 +285,7 @@
},
fischer: {
initial_time_range: [86400, 604800],
max_time_range: [86400, 604800],
time_increment_range: [43200, 604800],
},
Expand Down
26 changes: 24 additions & 2 deletions schema/Config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@
"description": "Allowed blitz times for the bot. Blitz is disabled by default, but you can enable it by providing acceptable time settings.",
"default": null
},
"allowed_rapid_settings": {
"anyOf": [
{
"type": "null"
},
{
"$ref": "#/definitions/TimeControlRanges"
}
],
"description": "Allowed rapid game times for bot."
},
"allowed_live_settings": {
"anyOf": [
{
Expand Down Expand Up @@ -552,16 +563,26 @@
"fischer": {
"type": "object",
"properties": {
"max_time_range": {
"initial_time_range": {
"type": "array",
"items": {
"type": "number"
},
"minItems": 2,
"maxItems": 2,
"description": "Range of acceptable main times in seconds.",
"description": "Range of acceptable initial times in seconds.",
"default": "[30, 600] for live games, [86400, 604800] for correspondence games"
},
"max_time_range": {
"type": "array",
"items": {
"type": "number"
},
"minItems": 2,
"maxItems": 2,
"description": "Range of acceptable max times in seconds.",
"default": "[5, 7200] for live games, [86400, 604800] for correspondence games"
},
"time_increment_range": {
"type": "array",
"items": {
Expand All @@ -574,6 +595,7 @@
}
},
"required": [
"initial_time_range",
"max_time_range",
"time_increment_range"
],
Expand Down
2 changes: 1 addition & 1 deletion src/Bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ignore_promise } from "./util";
import * as split2 from "split2";

import { Move } from "./types";
import { decodeMoves } from "goban/src/GoMath";
import { decodeMoves } from "goban-engine";
import { config, BotConfig } from "./config";
import { PvOutputParser } from "./PvOutputParser";
import { socket } from "./socket";
Expand Down
35 changes: 24 additions & 11 deletions src/Game.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { decodeMoves } from "goban/src/GoMath";
import { GoEngineConfig } from "goban/src/GoEngine";
import { GameChatAnalysisMessage } from "goban/src/protocol";
import { decodeMoves } from "goban-engine";
import { GobanEngineConfig } from "goban-engine";
import { protocol } from "goban-engine";
import { move2gtpvertex, ignore_promise } from "./util";
import { Move } from "./types";
import { Bot } from "./Bot";
Expand All @@ -23,7 +23,7 @@ export class Game extends EventEmitter<Events> {
connect_timeout: ReturnType<typeof setTimeout>;

game_id: number;
state: GoEngineConfig;
state: GobanEngineConfig;
opponent_evenodd: null | number;
greeted: boolean;
startup_timestamp: number;
Expand Down Expand Up @@ -387,21 +387,34 @@ export class Game extends EventEmitter<Events> {
const promises: Promise<void>[] = [];

this.verbose("Releasing bot(s)");
this.verbose("Bot count available: " + bot_pools.main.countAvailable());

if (this.bot) {
const bot = this.bot;
this.bot = undefined;
const using_opening_bot = this.using_opening_bot;
promises.push(
new Promise<void>((resolve, _reject) => {
console.log("Will release bots in ", bot.bot_config.release_delay, "ms");
setTimeout(() => {
bot.off("chat");
if (using_opening_bot) {
bot_pools.opening.release(bot);
} else {
bot_pools.main.release(bot);
try {
console.log("Releasing bot");
bot.off("chat");
if (using_opening_bot) {
console.log("Releasing opening bot");
bot_pools.opening.release(bot);
} else {
console.log("Releasing main bot");
bot_pools.main.release(bot);
console.log(
"released, Bot count available: " +
bot_pools.main.countAvailable(),
);
}
resolve();
} catch (e) {
console.error("Error releasing bot", e);
}
resolve();
}, bot.bot_config.release_delay);
}),
);
Expand Down Expand Up @@ -780,7 +793,7 @@ export class Game extends EventEmitter<Events> {
return `${color} ${player.username} [${this.state.width}x${this.state.height}] ${handicap}`;
}
sendChat(
msg: string | TranslatableString | GameChatAnalysisMessage,
msg: string | TranslatableString | protocol.GameChatAnalysisMessage,
move_number?: number,
channel: "main" | "malkovich" = "main",
): void {
Expand Down
8 changes: 4 additions & 4 deletions src/PvOutputParser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { char2num, num2char } from "goban/src/GoMath";
import { char2num, num2char } from "goban-engine";
//import { gtpchar2num } from "./Bot";
import { GameChatAnalysisMessage } from "goban/src/protocol";
import { protocol } from "goban-engine";
import { Game } from "./Game";
import { trace } from "./trace";

Expand Down Expand Up @@ -50,7 +50,7 @@ export class PvOutputParser {
name: string,
pv_move: string,
engine_analysis: EngineAnalysis,
): GameChatAnalysisMessage {
): protocol.GameChatAnalysisMessage {
return {
type: "analysis",
engine_analysis: engine_analysis,
Expand Down Expand Up @@ -134,7 +134,7 @@ export class PvOutputParser {
LEELA : this.postPvToChatSingleLine,
*/

let message: GameChatAnalysisMessage = null;
let message: protocol.GameChatAnalysisMessage | null = null;
switch (this.detected_engine) {
case "katago":
{
Expand Down
39 changes: 35 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ export interface Config {
*/
allowed_blitz_settings?: null | TimeControlRanges;

/** Allowed rapid game times for bot.
*/
allowed_rapid_settings?: null | TimeControlRanges;

/** Allowed live game times for bot.
*
* @default {"per_move_time_range": [10, 300], "main_time_range": [0, 3600], "periods_range": [1, 10]}
Expand Down Expand Up @@ -201,7 +205,7 @@ export interface Config {
/** Config version for internal use
* @hidden
*/
_config_version?: number;
_config_version?: 2;
}

export interface TimeControlRanges {
Expand Down Expand Up @@ -233,9 +237,14 @@ export interface TimeControlRanges {

/** Time control settings for fischer clocks */
fischer?: {
/** Range of acceptable main times in seconds.
/** Range of acceptable initial times in seconds.
* @default [30, 600] for live games, [86400, 604800] for correspondence games
*/
initial_time_range: [number, number];

/** Range of acceptable max times in seconds.
* @default [5, 7200] for live games, [86400, 604800] for correspondence games
*/
max_time_range: [number, number];

/** range of acceptable times for the time increment
Expand Down Expand Up @@ -382,6 +391,26 @@ function defaults(): Config {
status_update_frequency: 60000,
allowed_time_control_systems: ["fischer", "byoyomi", "simple"],
allowed_blitz_settings: null,

allowed_rapid_settings: {
simple: {
per_move_time_range: [5, 30],
},

byoyomi: {
main_time_range: [0, 3600],
period_time_range: [5, 30],
periods_range: [1, 10],
},

fischer: {
initial_time_range: [5, 600],
max_time_range: [5, 7200],
time_increment_range: [3, 30],
},

concurrent_games: 3,
},
allowed_live_settings: {
simple: {
per_move_time_range: [10, 300],
Expand All @@ -394,7 +423,8 @@ function defaults(): Config {
},

fischer: {
max_time_range: [30, 600],
initial_time_range: [10, 3600],
max_time_range: [5, 7200],
time_increment_range: [10, 300],
},

Expand All @@ -412,6 +442,7 @@ function defaults(): Config {
},

fischer: {
initial_time_range: [86400, 604800],
max_time_range: [86400, 604800],
time_increment_range: [43200, 604800],
},
Expand Down Expand Up @@ -657,7 +688,7 @@ function load_config_or_throw(): Config {
//console.info(yargs.argv);
//console.info(with_defaults);

with_defaults._config_version = 1;
with_defaults._config_version = 2;

return sanity_check_and_patch_config(with_defaults);
}
Expand Down
Loading

0 comments on commit b6dd13b

Please sign in to comment.