Skip to content

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

Open
d-kad wants to merge 4 commits into
gambitproject:masterfrom
d-kad:legal-labels
Open

Define and enforce a valid-label criterion for game objects (#944)#957
d-kad wants to merge 4 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).

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

1 participant