Skip to content

Commit

Permalink
Merge pull request #32 from Supalosa/fix/timeout
Browse files Browse the repository at this point in the history
(0.5.2) move timeout out of bot, so it won't die in real matches
  • Loading branch information
Supalosa authored Jan 25, 2024
2 parents 1877acf + 304e286 commit 3b04de0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@supalosa/chronodivide-bot",
"version": "0.5.1",
"version": "0.5.2",
"description": "Example bot for Chrono Divide",
"repository": "https://github.com/Supalosa/supalosa-chronodivide-bot",
"main": "dist/exampleBot.js",
Expand Down
6 changes: 0 additions & 6 deletions src/bot/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const DEBUG_STATE_UPDATE_INTERVAL_SECONDS = 6;

// Number of ticks per second at the base speed.
const NATURAL_TICK_RATE = 15;
const BOT_AUTO_SURRENDER_TIME_SECONDS = 7200; // 7200 = 2 hours (approx 30 mins in real time, given a game speed of 4)

export class SupalosaBot extends Bot {
private tickRatio?: number;
Expand Down Expand Up @@ -71,11 +70,6 @@ export class SupalosaBot extends Bot {

this.matchAwareness.onAiUpdate(game, myPlayer);

if (game.getCurrentTick() / NATURAL_TICK_RATE > BOT_AUTO_SURRENDER_TIME_SECONDS) {
this.logBotStatus(`Auto-surrendering after ${BOT_AUTO_SURRENDER_TIME_SECONDS} seconds.`);
this.actionsApi.quitGame();
}

// hacky resign condition
const armyUnits = game.getVisibleUnits(this.name, "self", (r) => r.isSelectableCombatant);
const mcvUnits = game.getVisibleUnits(
Expand Down
8 changes: 7 additions & 1 deletion src/exampleBot.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import "dotenv/config";
import { Agent, Bot, CreateBaseOpts, CreateOfflineOpts, CreateOnlineOpts, cdapi } from "@chronodivide/game-api";
import { SupalosaBot } from "./bot/bot.js";
import { off } from "process";

// The game will automatically end after this time. This is to handle stalemates.
const MAX_GAME_LENGTH_SECONDS: number | null = 7200; // 7200 = two hours

async function main() {
/*
Expand Down Expand Up @@ -105,6 +107,10 @@ async function main() {

const game = await cdapi.createGame(process.env.ONLINE_MATCH ? onlineSettings : offlineSettings1v1);
while (!game.isFinished()) {
if (!!MAX_GAME_LENGTH_SECONDS && game.getCurrentTick() / 15 > MAX_GAME_LENGTH_SECONDS) {
console.log(`Game forced to end due to timeout`);
break;
}
await game.update();
}

Expand Down

0 comments on commit 3b04de0

Please sign in to comment.