fix: Check alliance breakage once at launch, and is deterministic now (#2554)

## Description:

Removes the check to break alliance after nuke is launched, and alliance
breaking is now determined before tiles are randomly chosen for
destruction. (It is now slightly stricter, I believe, as a weighted
average calculation is a little tricky)

## 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

## Please put your Discord username so you can be contacted if a bug or
regression is found:
bibizu
This commit is contained in:
bibizu
2025-12-26 12:32:16 -08:00
committed by GitHub
parent 677a17d05a
commit 664d66613b
4 changed files with 72 additions and 7 deletions
+7
View File
@@ -926,6 +926,13 @@ export class GameImpl implements Game {
euclideanDistSquared(c1: TileRef, c2: TileRef): number {
return this._map.euclideanDistSquared(c1, c2);
}
circleSearch(
tile: TileRef,
radius: number,
filter?: (tile: TileRef, d2: number) => boolean,
): Set<TileRef> {
return this._map.circleSearch(tile, radius, filter);
}
bfs(
tile: TileRef,
filter: (gm: GameMap, tile: TileRef) => boolean,
+28
View File
@@ -39,6 +39,11 @@ export interface GameMap {
manhattanDist(c1: TileRef, c2: TileRef): number;
euclideanDistSquared(c1: TileRef, c2: TileRef): number;
circleSearch(
tile: TileRef,
radius: number,
filter?: (tile: TileRef, d2: number) => boolean,
): Set<TileRef>;
bfs(
tile: TileRef,
filter: (gm: GameMap, tile: TileRef) => boolean,
@@ -290,6 +295,29 @@ export class GameMapImpl implements GameMap {
const y = this.y(c1) - this.y(c2);
return x * x + y * y;
}
circleSearch(
tile: TileRef,
radius: number,
filter?: (tile: TileRef, d2: number) => boolean,
): Set<TileRef> {
const center = { x: this.x(tile), y: this.y(tile) };
const tiles: Set<TileRef> = new Set<TileRef>();
const minX = Math.max(0, center.x - radius);
const maxX = Math.min(this.width_ - 1, center.x + radius);
const minY = Math.max(0, center.y - radius);
const maxY = Math.min(this.height_ - 1, center.y + radius);
for (let i = minX; i <= maxX; ++i) {
for (let j = minY; j <= maxY; j++) {
const t = this.yToRef[j] + i;
const d2 = this.euclideanDistSquared(tile, t);
if (d2 > radius * radius) continue;
if (!filter || filter(t, d2)) {
tiles.add(t);
}
}
}
return tiles;
}
bfs(
tile: TileRef,
filter: (gm: GameMap, tile: TileRef) => boolean,
+7
View File
@@ -885,6 +885,13 @@ export class GameView implements GameMap {
euclideanDistSquared(c1: TileRef, c2: TileRef): number {
return this._map.euclideanDistSquared(c1, c2);
}
circleSearch(
tile: TileRef,
radius: number,
filter?: (tile: TileRef, d2: number) => boolean,
): Set<TileRef> {
return this._map.circleSearch(tile, radius, filter);
}
bfs(
tile: TileRef,
filter: (gm: GameMap, tile: TileRef) => boolean,