From 00872e080a1a42491b1aae7d8040ba7e2a30445a Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Thu, 29 May 2025 20:53:18 -0400 Subject: [PATCH] Simplify bots retaliation logic (#946) ## Description: Simplify bots retaliation logic. Do not counter-attack before reaching the trigger ratio. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com> --- src/core/execution/BotExecution.ts | 1 - src/core/execution/FakeHumanExecution.ts | 1 - src/core/execution/utils/BotBehavior.ts | 16 ++++++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/core/execution/BotExecution.ts b/src/core/execution/BotExecution.ts index 3b0354810..84d46768c 100644 --- a/src/core/execution/BotExecution.ts +++ b/src/core/execution/BotExecution.ts @@ -79,7 +79,6 @@ export class BotExecution implements Execution { } this.behavior.forgetOldEnemies(); - this.behavior.checkIncomingAttacks(); const enemy = this.behavior.selectRandomEnemy(); if (!enemy) return; if (!this.bot.sharesBorderWith(enemy)) return; diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index af71e77c2..4fa3ec7cd 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -262,7 +262,6 @@ export class FakeHumanExecution implements Execution { throw new Error("not initialized"); } this.behavior.forgetOldEnemies(); - this.behavior.checkIncomingAttacks(); this.behavior.assistAllies(); const enemy = this.behavior.selectEnemy(); if (!enemy) return; diff --git a/src/core/execution/utils/BotBehavior.ts b/src/core/execution/utils/BotBehavior.ts index afbb53331..e68a0c775 100644 --- a/src/core/execution/utils/BotBehavior.ts +++ b/src/core/execution/utils/BotBehavior.ts @@ -52,7 +52,7 @@ export class BotBehavior { } } - checkIncomingAttacks() { + private checkIncomingAttacks() { // Switch enemies if we're under attack const incomingAttacks = this.player.incomingAttacks(); if (incomingAttacks.length > 0) { @@ -109,6 +109,11 @@ export class BotBehavior { } } + // Retaliate against incoming attacks + if (this.enemy === null) { + this.checkIncomingAttacks(); + } + // Select the most hated player if (this.enemy === null) { const mostHated = this.player.allRelationsSorted()[0]; @@ -145,8 +150,15 @@ export class BotBehavior { this.enemy = neighbor; this.enemyUpdated = this.game.ticks(); } + } - // Select a traitor as an enemy + // Retaliate against incoming attacks + if (this.enemy === null) { + this.checkIncomingAttacks(); + } + + // Select a traitor as an enemy + if (this.enemy === null) { const traitors = this.player .neighbors() .filter((n) => n.isPlayer() && n.isTraitor()) as Player[];