From b82ada211394da92638b07c405a5cf74c53a3221 Mon Sep 17 00:00:00 2001 From: Mattia Migliorini Date: Fri, 27 Feb 2026 08:57:17 +0100 Subject: [PATCH] Account for cascading collisions --- src/core/game/GameImpl.ts | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/core/game/GameImpl.ts b/src/core/game/GameImpl.ts index f146fe587..093d4d848 100644 --- a/src/core/game/GameImpl.ts +++ b/src/core/game/GameImpl.ts @@ -236,18 +236,23 @@ export class GameImpl implements Game { } } - // Collision check: remove any renames that collide with existing team - // names (excluding the team being renamed) or with another rename. - const existingNames = new Set( - this.playerTeams.filter((t) => !renameMap.has(t)), - ); - const newNames = Array.from(renameMap.values()); - for (const [oldTeam, newName] of renameMap.entries()) { - if ( - existingNames.has(newName) || - newNames.filter((n) => n === newName).length > 1 - ) { - renameMap.delete(oldTeam); + // Collision check: repeatedly remove renames that collide with existing + // team names or with each other until no more removals occur. + let changed = true; + while (changed) { + changed = false; + const existingNames = new Set( + this.playerTeams.filter((t) => !renameMap.has(t)), + ); + const newNames = Array.from(renameMap.values()); + for (const [oldTeam, newName] of renameMap.entries()) { + if ( + existingNames.has(newName) || + newNames.filter((n) => n === newName).length > 1 + ) { + renameMap.delete(oldTeam); + changed = true; + } } }