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>
This commit is contained in:
Scott Anderson
2025-05-29 20:53:18 -04:00
committed by evanpelle
parent 41481f190c
commit 00872e080a
3 changed files with 14 additions and 4 deletions
-1
View File
@@ -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;
-1
View File
@@ -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;
+14 -2
View File
@@ -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[];