Skip to content

Define and enforce a valid-label criterion for game objects (#944)#957

Merged
tturocy merged 6 commits into
gambitproject:masterfrom
d-kad:legal-labels
Jun 25, 2026
Merged

Define and enforce a valid-label criterion for game objects (#944)#957
tturocy merged 6 commits into
gambitproject:masterfrom
d-kad:legal-labels

Conversation

@d-kad

@d-kad d-kad commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Issues closed by this PR

Description of the changes in this PR

This PR defines and enforces a single criterion for valid game-object labels, centrally at the C++ level.

A label is valid if it consists only of printable ASCII characters and spaces, does not begin or end with a space, and does not contain two consecutive spaces. The empty label remains valid. The definition is enforced in one place (IsValidLabel/CheckLabel in game.h) so that widening it to permit Unicode in 17.0 (#862) is a localised change.

  • CheckLabel is called from all six SetLabel methods (outcome, action, infoset, strategy, player, node) and from the GameStrategyRep constructor.
  • In pygambit, the six SetLabel declarations and NewStrategy now map the C++ exception to ValueError (except +ValueError); an invalid label raises ValueError.
  • add_strategy now encodes the label as ASCII, consistent with the other accessors; a non-ASCII label fails at the boundary with UnicodeEncodeError.

Tests add per-type valid/invalid/non-ASCII coverage (constants in tests/games.py).

@tturocy

tturocy commented Jun 25, 2026

Copy link
Copy Markdown
Member

@d-kad This looks good for a start. I did check and there are some paths in the GUI which aren't catching exceptions, so if we merge this without adding at least some crude defensive handlers we're creating a bad regression (it completely crashes the GUI!) so I need to look at those first before we can accept (unfortunately we can't treat them entirely as separate issues as #945 wishes were true!)

@tturocy tturocy merged commit 2af8dc9 into gambitproject:master Jun 25, 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]: Define and enforce criteria for legal labels in game representation

2 participants