From 0281db46fad86b181b456b38cfeac387c4b26bcf Mon Sep 17 00:00:00 2001 From: evanpelle Date: Thu, 29 Aug 2024 20:19:56 -0700 Subject: [PATCH] make bots more likely to attack larger border --- TODO.txt | 5 +++- src/core/configuration/DevConfig.ts | 2 +- src/core/execution/BotExecution.ts | 38 ++++++++++++++++------------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/TODO.txt b/TODO.txt index 1b81a98dd..d7134491c 100644 --- a/TODO.txt +++ b/TODO.txt @@ -54,9 +54,12 @@ * BUG: players attack each other same time creates islands DONE 8/28/2024 * make bot spawn better DONE 8/28/2024 * make UX for attacking TerraNullius by boat better DONE 8/29/2024 -* make bot territory less funky (more likely attack neighbors with larger border) +* make bot territory less funky (more likely attack neighbors with larger border) DONE 8/29/2024 * PERF: use hierarchical a* search for boats * PERF: precompute spawns +* PERF: load terrain map async +* PERF: enable CDN +* enable load balancing metrics * end game when no players left (or after 1 hour or so?) * boats can go around the world * Add terrain elevation to map diff --git a/src/core/configuration/DevConfig.ts b/src/core/configuration/DevConfig.ts index 40d50ccca..5d82278d4 100644 --- a/src/core/configuration/DevConfig.ts +++ b/src/core/configuration/DevConfig.ts @@ -19,7 +19,7 @@ export const devConfig = new class extends DefaultConfig { return devPlayerConfig } numBots(): number { - return 50 + return 250 } } diff --git a/src/core/execution/BotExecution.ts b/src/core/execution/BotExecution.ts index e27386cb6..c70c739ac 100644 --- a/src/core/execution/BotExecution.ts +++ b/src/core/execution/BotExecution.ts @@ -10,7 +10,7 @@ export class BotExecution implements Execution { private random: PseudoRandom; private attackRate: number private mg: MutableGame - private neighborsTerra = true + private neighborsTerraNullius = true constructor(private bot: MutablePlayer) { @@ -37,26 +37,30 @@ export class BotExecution implements Execution { return } - if (ticks % this.attackRate == 0) { - if (this.neighborsTerra) { - for (const b of this.bot.borderTiles()) { - for (const n of b.neighbors()) { - if (n.owner() == this.mg.terraNullius() && n.isLand()) { - this.sendAttack(this.mg.terraNullius()) - return - } + if (ticks % this.attackRate != 0) { + return + } + + if (this.neighborsTerraNullius) { + for (const b of this.bot.borderTiles()) { + for (const n of b.neighbors()) { + if (n.owner() == this.mg.terraNullius() && n.isLand()) { + this.sendAttack(this.mg.terraNullius()) + return } } - this.neighborsTerra = false } - - const ns = this.bot.neighbors() - if (ns.length == 0) { - return - } - const toAttack = ns[this.random.nextInt(0, ns.length)] - this.sendAttack(toAttack) + this.neighborsTerraNullius = false } + + const border = Array.from(this.bot.borderTiles()).flatMap(t => t.neighbors()).filter(t => t.hasOwner() && t.owner() != this.bot) + + if (border.length == 0) { + return + } + + const toAttack = border[this.random.nextInt(0, border.length)] + this.sendAttack(toAttack.owner()) } sendAttack(toAttack: Player | TerraNullius) {