Skip to content

Return an actual firing sequence from the Gonality Game's verbose mode#34

Open
Copilot wants to merge 2 commits into
mainfrom
copilot/implement-gonality-game-tools
Open

Return an actual firing sequence from the Gonality Game's verbose mode#34
Copilot wants to merge 2 commits into
mainfrom
copilot/implement-gonality-game-tools

Conversation

Copilot AI commented Apr 21, 2026

Copy link
Copy Markdown

CFGonality._find_winning_sequence was a stub returning [], so play_gonality_game(..., verbose=True) reported Player A as the winner without ever showing how the debt was resolved. The broader gonality / treewidth / Dhar / Platonic-solid infrastructure called for in issue #6 is already in place; this fills the one concrete remaining placeholder in the gonality-game path.

Changes

  • chipfiring/CFGonality.py — Implement _find_winning_sequence by reusing the existing DharAlgorithm in an EWD-style loop:
    • Pick q as the min-degree vertex (matching algo.EWD).
    • Iteratively run Dhar's burning algorithm to obtain a maximal legal firing set on V − {q}, fire it, and append the fired vertex names (sorted) to the returned sequence.
    • Operate on a copy of the divisor so the caller's input is never mutated.
    • Return [] for already-effective inputs and for non-winnable inputs (detected via residual debt at q after q-reduction).
    • Defensive O(|V|²) iteration cap to guarantee termination on pathological inputs.
  • tests/test_cfgonality.py — New TestFindWinningSequence covering: already-effective input, debt resolution on K₃ and on a path graph (with end-to-end verification that applying the returned firings produces an effective divisor), non-winnable input, input non-mutation, and verbose play_gonality_game.

Example

from chipfiring import CFGraph, CFDivisor, play_gonality_game

g = CFGraph({"A", "B", "C"}, [("A", "B", 1), ("B", "C", 1), ("A", "C", 1)])
placement = CFDivisor(g, [("A", 2), ("B", 0), ("C", 0)])  # Player A's 2 chips on A
result = play_gonality_game(g, 2, placement, "B", verbose=True)  # Player B targets B

result.player_a_wins      # True
result.winning_sequence   # ['A']  -- previously always []

Agent-Logs-Url: https://github.com/DhyeyMavani2003/chipfiring/sessions/236cbaa8-547e-4b16-99f9-25ec2f69353a

Co-authored-by: DhyeyMavani2003 <82772894+DhyeyMavani2003@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement gonality game and related algorithms and tools Return an actual firing sequence from the Gonality Game's verbose mode Apr 21, 2026
Copilot AI requested a review from DhyeyMavani2003 April 21, 2026 03:36
@DhyeyMavani2003 DhyeyMavani2003 marked this pull request as ready for review April 21, 2026 03:46
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.

Implement Gonality Game and other gonality related algorithms + tools like TreeWidth

2 participants