Skip to content

Add GameSubgame class and subgame API#909

Closed
d-kad wants to merge 12 commits into
gambitproject:masterfrom
d-kad:gamesubgame
Closed

Add GameSubgame class and subgame API#909
d-kad wants to merge 12 commits into
gambitproject:masterfrom
d-kad:gamesubgame

Conversation

@d-kad
Copy link
Copy Markdown
Contributor

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

Issues closed by this PR

Description of the changes in this PR

Adds GameSubgameRep (C++) and Subgame (Python), a first-class object representing a subgame, building on the subgame-root detection from 16.6.0 (#584).

On Subgame: .root, .parent (None for the root subgame), .children, and .difference (infosets in this subgame but not in any of its child subgames).
On Game: .root_subgame (None if the game has no subgames), .subgames (postorder), .terminal_subgames, and .subgame_root(infoset). Subgames use the same lazy-build/invalidation lifecycle as strategies.

Parent/child links live on the Subgame object rather than on GameRep, for consistency with node.parent, infoset.player, etc.; collection-level queries stay on Game.

Makes IsSubgameRoot() O(1) -- closes an old TODO.

Not implemented: GetInfosets(subgame, player) from the description of #585difference is the closest piece (unfiltered by player) -- will be shipped separately as this PR is pretty big already.

How to review this PR

  • Review src/games/gametree.cc (gametree.h, game.h): detection (Phases 1–2 of BuildSubgameRoots) is the existing 16.6.0 algorithm; new here is the Phase 3 subgame-tree/difference construction.
  • pytest tests/test_node.py — covers postorder, parent/child, terminal subgames, and the difference partition on subgame-8-roots.efg, plus the trivial-game edge case.

@d-kad d-kad closed this Jun 3, 2026
@d-kad d-kad deleted the gamesubgame branch June 3, 2026 14:31
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: Implement concept of GameSubgameRep in C++/GameSubgame in Python

1 participant