Skip to content

Commit c02d2b1

Browse files
committed
Optimized lastNukeSent a bit (to respect nuke radius)
1 parent 2fee823 commit c02d2b1

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

src/core/execution/nation/NationNukeBehavior.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ import { EMOJI_NUKE, NationEmojiBehavior } from "./NationEmojiBehavior";
2121
import { randTerritoryTileArray } from "./NationUtils";
2222

2323
export class NationNukeBehavior {
24-
private readonly lastNukeSent: [Tick, TileRef][] = [];
24+
private readonly recentlySentNukes: [
25+
Tick,
26+
TileRef,
27+
UnitType.AtomBomb | UnitType.HydrogenBomb,
28+
][] = [];
2529
private atomBombsLaunched = 0;
2630
private atomBombPerceivedCost = this.cost(UnitType.AtomBomb);
2731
private hydrogenBombsLaunched = 0;
@@ -350,13 +354,13 @@ export class NationNukeBehavior {
350354
}
351355

352356
private removeOldNukeEvents() {
353-
const maxAge = 500;
357+
const maxAge = 600; // 600 ticks = 1 minute
354358
const tick = this.game.ticks();
355359
while (
356-
this.lastNukeSent.length > 0 &&
357-
this.lastNukeSent[0][0] + maxAge < tick
360+
this.recentlySentNukes.length > 0 &&
361+
this.recentlySentNukes[0][0] + maxAge < tick
358362
) {
359-
this.lastNukeSent.shift();
363+
this.recentlySentNukes.shift();
360364
}
361365
}
362366

@@ -565,9 +569,14 @@ export class NationNukeBehavior {
565569
tileValue = Math.max(baseTileValue * 0.2, tileValue - distancePenalty); // Keep at least 20% of structure value
566570

567571
// Don't target near recent targets
568-
const dist25 = euclDistFN(tile, 25, false);
569-
tileValue -= this.lastNukeSent
570-
.filter(([_tick, tile]) => dist25(this.game, tile))
572+
tileValue -= this.recentlySentNukes
573+
.filter(([_tick, recentTile, recentNukeType]) => {
574+
const recentInnerRadius = this.game
575+
.config()
576+
.nukeMagnitudes(recentNukeType).inner;
577+
const distSquared = this.game.euclideanDistSquared(tile, recentTile);
578+
return distSquared <= recentInnerRadius * recentInnerRadius;
579+
})
571580
.map((_) => 1_000_000)
572581
.reduce((prev, cur) => prev + cur, 0);
573582

@@ -580,7 +589,7 @@ export class NationNukeBehavior {
580589
targetPlayer: Player,
581590
) {
582591
const tick = this.game.ticks();
583-
this.lastNukeSent.push([tick, tile]);
592+
this.recentlySentNukes.push([tick, tile, nukeType]);
584593
if (nukeType === UnitType.AtomBomb) {
585594
this.atomBombsLaunched++;
586595
// Increase perceived cost by 25% each time to simulate saving up for a MIRV (higher than hydro to make atom bombs less attractive for the lategame)

0 commit comments

Comments
 (0)