fix: define colors up to max player ID for non-consecutive IDs#60
Open
ravjot07 wants to merge 1 commit intogambitproject:mainfrom
Open
fix: define colors up to max player ID for non-consecutive IDs#60ravjot07 wants to merge 1 commit intogambitproject:mainfrom
ravjot07 wants to merge 1 commit intogambitproject:mainfrom
Conversation
color_definitions() names colors p1rgb, p2rgb, …, p{N}rgb sequentially,
and get_player_color() looks up p{player}rgb by actual player number.
When player IDs are non-consecutive (e.g. 1, 2, 5) the old code passed
len(player_nums)=3, leaving p5rgb undefined and causing a LaTeX error.
Use max(player_nums) instead so all referenced colors are defined.
Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
For distinctipy and colorblind, LaTeX colour names are p1rgb, p2rgb, … and get_player_color() uses the actual player index (p{player}rgb). color_definitions() was driven by num_players taken as len(player_ids) for .ef games.
If a game used non-consecutive player IDs (e.g. 1, 2, 5), only three colours (p1rgb–p3rgb) were defined while the tree still referenced p5rgb, which broke LaTeX compilation with an undefined colour.
Solution
When inferring num_players from .ef player N lines, use max(player_nums) instead of len(player_nums), so the palette spans every ID that can appear in the diagram.
pygambit games are unchanged: num_players = len(game.players) still matches consecutive Gambit player indices.