Repository navigation
Implement Game.relabel_players to reassign the labels of a game's players. - #1065
Merged
Merged
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
# 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issues closed by this PR
relabel_players#1058Description of the changes in this PR
Adds
Game.relabel_players(labels, strict=True), which reassigns the labels of the game's players.labelsmaps 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 inrelabel_actionsandrelabel_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
ValueErrorrather than being ignored under
strict=False; and in an extensive game"Chance"remains rejectedas a replacement (cf.
CheckPlayerLabel).GameRep::CheckPlayerLabelis extended with an ignore set so that the replacements can be validatedagainst the post-relabelling state.
Assigning to
Player.labelis removed (cf. removedStrategy.label,Action.label).