Skip to content

Implement Game.relabel_strategies to reassign the strategy labels of a player. - #1047

Merged
tturocy merged 9 commits into
gambitproject:masterfrom
d-kad:relabel_strategies
Aug 18, 2026
Merged

Implement Game.relabel_strategies to reassign the strategy labels of a player.#1047
tturocy merged 9 commits into
gambitproject:masterfrom
d-kad:relabel_strategies

Conversation

@d-kad

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

Copy link
Copy Markdown
Contributor

Description of the changes in this PR

Adds Game.relabel_strategies(player, labels, strict=True), which reassigns the labels of a player's strategies
in a normal form game (not defined for extensive form games).
labels maps current labels to their replacements, and the reassignment is simultaneous, so labels can be
swapped directly. Strategies are not reordered: each relabelled strategy keeps its position.
With strict=False, keys matching no current strategy are ignored, as in relabel_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.label is removed (cf. removed Action.label).

d-kad and others added 9 commits August 14, 2026 08:56
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>
@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

@tturocy
tturocy merged commit 6f526d5 into gambitproject:master Aug 18, 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.

2 participants