Implement Game.relabel_strategies to reassign the strategy labels of a player. - #1047
Merged
Merged
Conversation
GameTableRep::NewPlayer created the player's sole strategy via
GamePlayerRep's constructor, which leaves it labeled "" until something
else fixes it up. The GUI's DoNewPlayer patched this after the fact with
SetLabel("1"), but pygambit's add_player had no equivalent patch, so it
silently returned a player whose strategy violated the nonempty/unique
label invariant enforced everywhere else. NewPlayer now assigns the
valid default label directly at construction, matching how
GameTableRep's bulk constructor, GameAGGRep, and GameBAGGRep already
initialize strategies; the GUI's patch-up is no longer needed.
BuildNfg now relabels a player's parsed strategies via RelabelStrategies
instead of the ad hoc scratch-label trick in RelabelWithoutCollision.
NormalizeGameLabels's strategy-normalization branch is removed: every
strategic-form construction path already guarantees unique, nonempty
per-player strategy labels by the time it would run, so it never had
anything to fix.
With no callers left, GameStrategyRep::SetLabel is deleted, along with
the now-dead gambit.pxd binding for it -- the same treatment
GameActionRep::SetLabel got in gambitproject#1031.
test_file.py already had a _parse_nfg helper but no coverage for strategy
label parsing, despite thorough .efg action-label coverage alongside it.
Covers empty and duplicate raw labels, and the case that matters most:
a file whose strategy labels are the reverse of the default numeric
labels ("2", "1" colliding with "1", "2") BuildNfg assigns before
relabeling via RelabelStrategies.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
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.
Description of the changes in this PR
Adds
Game.relabel_strategies(player, labels, strict=True), which reassigns the labels of a player's strategiesin a normal form game (not defined for extensive form games).
labelsmaps current labels to their replacements, and the reassignment is simultaneous, so labels can beswapped directly. Strategies are not reordered: each relabelled strategy keeps its position.
With
strict=False, keys matching no current strategy are ignored, as inrelabel_actions.The operation is scoped to a player, mirroring
relabel_actions' scoping to an information set:actions are strategies in the agent form of a game.
Assigning to
Strategy.labelis removed (cf. removedAction.label).