Skip to content

feat: implement dynamic distinctipy and colorblind-friendly schemes (#14)#52

Open
XinkeLi-UChicago wants to merge 3 commits intogambitproject:mainfrom
XinkeLi-UChicago:issue-14-colors
Open

feat: implement dynamic distinctipy and colorblind-friendly schemes (#14)#52
XinkeLi-UChicago wants to merge 3 commits intogambitproject:mainfrom
XinkeLi-UChicago:issue-14-colors

Conversation

@XinkeLi-UChicago
Copy link

Closes #14

Description

This PR implements the requested enhancements for game tree coloring, including a dynamic high-contrast scheme and an accessibility-focused option:

  1. Robust limits for the "gambit" scheme: Added a defensive check in get_player_color. If a game exceeds 6 players, it now raises a descriptive ValueError recommending the new dynamic schemes, replacing the silent fallback to black with an explicit error.
  2. Dynamic "distinctipy" scheme integration: Introduced a new color scheme using the distinctipy library. It dynamically generates high-contrast, deterministic colors (via a fixed rng seed) for an arbitrary number of players. The chance node color and background colors are explicitly excluded from generation to ensure visual clarity.
  3. Accessibility-focused "colorblind" scheme (Bonus): To ensure inclusive visualization, I added a colorblind scheme leveraging distinctipy's built-in Deuteranomaly simulation. This allows game trees to be easily interpreted by individuals with the most common form of color vision deficiency.

Changes

  • src/draw_tree/core.py: Modified get_player_color, color_definitions, and generate_tikz to support dynamic player counting and multiple color schemes.
  • pyproject.toml: Added distinctipy to the runtime dependencies.

Implementation Notes

  • The required number of colors is scanned efficiently from the Game object or the .ef file.
  • Edge case considered: For .ef files using inline player definitions, the scanner safely falls back to generating 6 distinct colors to guarantee rendering stability.

How to test

# 1. Existing gambit scheme still works for <= 6 players
draw_tree(g, color_scheme="gambit")

# 2. Error is explicitly raised for >6 player games with gambit scheme
# draw_tree(large_game, color_scheme="gambit")  # raises ValueError

# 3. New distinctipy scheme handles any number of players deterministically
draw_tree(g, color_scheme="distinctipy")

# 4. Colorblind-friendly scheme for accessible visualizations
draw_tree(g, color_scheme="colorblind")

@edwardchalstrey1
Copy link
Member

Thanks for this @XinkeLi-UChicago - we've received your email regarding the project proposal and looking into a different project idea - give us a bit of time to respond properly and I will review this PR once we've got that sorted. Thanks!

@XinkeLi-UChicago
Copy link
Author

XinkeLi-UChicago commented Mar 9, 2026

Thanks @edwardchalstrey1! Just a heads-up: the earlier CI failures were due to an edge case with unassigned nodes (player < 0). I've pushed a fix in my latest commit.
Take your time on the Idea 9 or Idea 6 discussion -- happy to wait.

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.

[Good first issue]: Add different options for colouring game graphics by player

2 participants