bugfix: ColorAllocator not copying fallbackColors causing it to be empty, causing npes

This commit is contained in:
evanpelle
2025-06-10 14:43:37 -07:00
parent 4b3447dcf6
commit 80cfccc811
2 changed files with 13 additions and 3 deletions
+1 -1
View File
@@ -349,7 +349,7 @@ export class ColorAllocator {
return this.assigned.get(id)!;
}
if (this.availableColors.length === 0) {
this.availableColors = this.fallbackColors;
this.availableColors = [...this.fallbackColors];
}
const index = 0;
const color = this.availableColors.splice(index, 1)[0];
+12 -2
View File
@@ -579,9 +579,19 @@ export class DefaultConfig implements Config {
const densityRatio = defenderDensity / attackerDensity;
const attackDefenseRatio = defender.troops() / attackTroops;
if (attacker.type() === PlayerType.Human) {
console.log("densityRatio", densityRatio);
console.log("attackDefenseRatio", attackDefenseRatio);
console.log(
"modifier",
Math.sqrt(densityRatio * attackDefenseRatio) / 2,
);
}
const modifier = within(
Math.sqrt(densityRatio * attackDefenseRatio),
0.6,
Math.sqrt(densityRatio * attackDefenseRatio) / 2,
0.5,
2,
);