Skip to content

Implement Game.set_actions to declare the action list of an information set. - #1040

Merged
tturocy merged 18 commits into
gambitproject:masterfrom
d-kad:set_actions
Aug 19, 2026
Merged

tturocy merged 18 commits into
gambitproject:masterfrom
d-kad:set_actions

Conversation

@d-kad

@d-kad d-kad commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Issues closed by this PR

Description of the changes in this PR

Adds Game.set_actions(infoset, actions, probs=None, drop=False, add=True), declaring the full ordered
action list of an information set, matching by label. Entries matching current labels keep those actions and
their subtrees, in the declared position, so listing the current labels in a new order reorders the actions;
entries matching no current action create new actions with terminal stubs at every member;
current actions not declared are deleted along with their subtrees.
Deletion is destructive, so drop must be set to confirm it.

Game.add_action and Game.delete_action are removed.

At an event, the probability distribution is declared with the actions: probs takes a sequence or a mapping,
exactly as make_event does, resolved against the declared actions, and sum to one. A pure reordering
needs no probs, since each probability stays with its action. Deleting an action therefore never renormalizes: the distribution over what remains is explicitly declared.

The last commit removes DeleteAction and NormalizeChanceProbs (its only caller) from the C++ core: after
Game.delete_action's removal neither has any caller in the tree.
@tturocy let me know if I should drop this last commit if you would rather keep them.

@d-kad
d-kad requested a review from tturocy August 13, 2026 08:26
@d-kad d-kad added c++ Items which involve writing in C++ enhancement cython Items which involve coding in Cython labels Aug 13, 2026
@d-kad d-kad added this to the gambit-17.0.0.alpha.1 milestone Aug 13, 2026
# Conflicts:
#	src/games/gametree.cc
#	tests/test_infosets.py

@tturocy tturocy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly looking OK, but we need to enhance the test coverage - specifically missing would seem to be permutations of more than two actions, or moving actions - and specifically making sure that when actions are moved the whole subtree underneath them goes with it (at the moment looks like only actions above terminal nodes are tried?)

tturocy and others added 3 commits August 14, 2026 20:50
…by remove InsertAction from C++ as now fully superseded.
…changed

The cache was only rebuilt when the total node count changed, on the
assumption that a same-count edit could only be a relabel. But an edit
that drops one node and creates another in the same operation (e.g.
simultaneously adding and removing actions at an information set)
also leaves the count unchanged while swapping out which nodes exist,
so the stale map got indexed with an unrecognized node and
null-dereferenced. Now also check that every node in the freshly
computed layout is one the cache already has an entry for.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…ctions

Replace the fixed-row "Move properties" dialog with a variable-length
action editor backed by SetActions/RelabelActions: actions can now be
added, reordered, and deleted (reversibly, until OK is clicked -- a
newly added action has nothing to preserve, so deleting one removes
it outright instead) directly in the dialog. New, renamed, and invalid
rows are colour- and weight-coded so their status doesn't depend on
colour perception alone.

This supersedes the standalone "Insert action" menu command, now
removed along with its GameDocument command. Renamed the dialog (and
its context-menu label) to "Edit move" to match, and documented the
new behavior in doc/gui.efg.rst.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@tturocy

tturocy commented Aug 14, 2026

Copy link
Copy Markdown
Member

@rahulsavani @d-kad I have drafted a new "Edit move" dialog which allows the exercise of the whole of SetActions and RelabelActions. As a result InsertAction has been removed. Meanwhile there was no way to delete an action in the GUI (possible in the underlying code but at some point got lost), and also it's never been possible to reorder actions in a single option without some complex dancing of copying subtrees manually.

Please have a go and comment as it surely can be improved, though I think it's a big step up from what we had!

@d-kad

d-kad commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

I tested the edit move dialog, mostly good, the only bug I found is that reassigning the player raises "Dereferencing an invalidated object"

Screenshot 2026-08-17 at 14 28 47 Screenshot 2026-08-17 at 14 28 53

tturocy and others added 4 commits August 18, 2026 20:07
OnEditMove held onto a single GameInfoset handle across the whole
operation, but reassigning the player calls DoSetPlayer, which reforms
the information set's members into a brand-new GameInfosetRep via
MakeInfoset -- invalidating the original handle, since it's left with
no members. The rest of the function then went on to dereference that
stale handle (IsChanceInfoset(), and the DoSetActions() call), raising
"Dereferencing an invalidated object" instead of completing. Re-fetch
the information set through the (still valid) selected node after a
player reassignment.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@tturocy
tturocy merged commit c9ba12a into gambitproject:master Aug 19, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Items which involve writing in C++ cython Items which involve coding in Cython enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENH: Consolidate add_action/delete_action into single operation

2 participants