Refactor attack rate

This commit is contained in:
Scott Anderson
2025-04-02 23:23:40 -04:00
parent 769080e289
commit 2778d1e480
2 changed files with 9 additions and 6 deletions
+3 -3
View File
@@ -13,12 +13,14 @@ export class BotExecution implements Execution {
private active = true;
private random: PseudoRandom;
private attackRate: number;
private attackTick: number;
private mg: Game;
private neighborsTerraNullius = true;
constructor(private bot: Player) {
this.random = new PseudoRandom(simpleHash(bot.id()));
this.attackRate = this.random.nextInt(10, 50);
this.attackTick = this.random.nextInt(0, this.attackRate - 1);
}
activeDuringSpawnPhase(): boolean {
return false;
@@ -36,9 +38,7 @@ export class BotExecution implements Execution {
return;
}
if (ticks % this.attackRate != 0) {
return;
}
if (ticks % this.attackRate != this.attackTick) return;
this.bot.incomingAllianceRequests().forEach((ar) => {
if (ar.requestor().isTraitor()) {
+6 -3
View File
@@ -44,6 +44,9 @@ export class FakeHumanExecution implements Execution {
private lastNukeSent: [Tick, TileRef][] = [];
private embargoMalusApplied = new Set<PlayerID>();
private attackRate: number;
private attackTick: number;
constructor(
gameID: GameID,
private playerInfo: PlayerInfo,
@@ -51,6 +54,8 @@ export class FakeHumanExecution implements Execution {
this.random = new PseudoRandom(
simpleHash(playerInfo.id) + simpleHash(gameID),
);
this.attackRate = this.random.nextInt(40, 80);
this.attackTick = this.random.nextInt(0, this.attackRate - 1);
}
init(mg: Game, ticks: number) {
@@ -128,9 +133,7 @@ export class FakeHumanExecution implements Execution {
return;
}
if (ticks % this.random.nextInt(40, 80) != 0) {
return;
}
if (ticks % this.attackRate != this.attackTick) return;
if (
this.player.troops() > 100_000 &&