Skip to content

Implement Game.relabel_players to reassign the labels of a game's players. - #1065

Merged
tturocy merged 7 commits into
gambitproject:masterfrom
d-kad:relabel_players
Aug 20, 2026
Merged

tturocy merged 7 commits into
gambitproject:masterfrom
d-kad:relabel_players

Conversation

@d-kad

@d-kad d-kad commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Issues closed by this PR

Description of the changes in this PR

Adds Game.relabel_players(labels, strict=True), which reassigns the labels of the game's players.
labels maps current labels to their replacements, and the reassignment is simultaneous,
so labels can be swapped directly. Players are not reordered: each relabelled player keeps its position.
With strict=False, keys matching no current player are ignored, as in relabel_actions and relabel_strategies.

The operation is scoped to the game; it is defined for extensive as well as strategic games.

The chance player is not part of the operation. Its label is reserved, so a key equal to it raises ValueError
rather than being ignored under strict=False; and in an extensive game "Chance" remains rejected
as a replacement (cf. CheckPlayerLabel).

GameRep::CheckPlayerLabel is extended with an ignore set so that the replacements can be validated
against the post-relabelling state.

Assigning to Player.label is removed (cf. removed Strategy.label, Action.label).

@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@d-kad d-kad added this to the gambit-17.0.0.alpha.2 milestone Aug 20, 2026
@d-kad
d-kad requested a review from tturocy August 20, 2026 08:10
tturocy and others added 2 commits August 20, 2026 14:04
# Conflicts:
#	ChangeLog
#	src/pygambit/game.pxi
…elabelPlayers

Mirrors the treatment GameActionRep::SetLabel and GameStrategyRep::SetLabel
already got (gambitproject#1031, gambitproject#1047): with Game.relabel_players now the sole public
way to rename a player, the underlying per-object setter is no longer
needed.

The GUI's Game Properties dialog previously renamed players one at a time
via DoSetPlayerLabel, which could fail to swap two players' labels: renaming
the first collided with the second's still-current label, even though the
dialog's own validation (checking the proposed final state) saw nothing
wrong. DoSetPlayerLabel is replaced with DoRelabelPlayers, which builds a
single old-label -> new-label map from all changed rows and applies it in
one RelabelPlayers call, the same batching DoSetStrategies already uses for
strategies. NewTableDocument's default "Player N" labeling is batched the
same way.

With SetLabel gone, the two remaining internal callers in file.cc are
updated: BuildNfg's RelabelWithoutCollision scratch-label trick for parsed
player labels is replaced by a direct RelabelPlayers call (RelabelPlayers's
simultaneous resolution makes the scratch pass unnecessary, so
RelabelWithoutCollision is deleted with no callers left), and
NormalizeGameLabels's generic per-element setter is given a
RelabelPlayers-based lambda for the player branch, leaving the outcome
branch untouched.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@tturocy
tturocy merged commit 1e8e31d into gambitproject:master Aug 20, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENH]: Write relabel_players

2 participants