diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index fae0be710..7326375f1 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -182,7 +182,6 @@ export class FakeHumanExecution implements Execution { this.player.breakAlliance(alliance); - // Successfully broken an alliance return true; } @@ -259,22 +258,25 @@ export class FakeHumanExecution implements Execution { return false; } + const shouldAttack = this.attackChance(other); + // Consider betrayal for allies - if (this.player.isAlliedWith(other)) { - const canProceed = this.maybeConsiderBetrayal(other); - return canProceed; + if (shouldAttack && this.player.isAlliedWith(other)) { + return this.maybeConsiderBetrayal(other); } - if (this.player.isFriendly(other)) { - if (this.shouldDiscourageAttack(other)) { - return this.random.chance(200); - } - return this.random.chance(50); + return shouldAttack; + } + + private attackChance(other: Player): boolean { + if (this.player === null) throw new Error("not initialized"); + + if (this.player.isAlliedWith(other)) { + return this.shouldDiscourageAttack(other) + ? this.random.chance(200) + : this.random.chance(50); } else { - if (this.shouldDiscourageAttack(other)) { - return this.random.chance(4); - } - return true; + return this.shouldDiscourageAttack(other) ? this.random.chance(4) : true; } }