Refactor triangle.c for legibility - #1
Open
LouieVirosa wants to merge 1 commit into
Open
Conversation
Collapse the six-fold direction handling in num_moves() and get_new_state() into a single DIRECTIONS table plus is_valid_jump()/apply_move() helpers, so adding or tweaking a jump direction is a one-line change instead of ~40 lines duplicated across two functions. Extract argument parsing out of main(), tidy init_game() indentation, and replace the column_max[] lookup table with the equivalent direct row index. Behavior verified identical to master across the sample inputs (0,0), (2,1), (4,2), (0,0)->(4,0), (3,1)->(4,4), and the error paths. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
num_moves()andget_new_state()into a singleDIRECTIONStable plusis_valid_jump()/apply_move()helpers. Adding or changing a jump direction is now a one-line table edit instead of ~40 lines duplicated across two functions.main()intoparse_args().init_game()indentation, drop the trivialcolumn_max[5] = {0,1,2,3,4}lookup in favor of using the row index directly, and introduce aBOARD_SIZEconstant intriangle.h.triangle.c: ~115 fewer lines despite added comments.No behavioral change. Same DFS exploration order, same move enumeration, same output format.
Test plan
%lluformat warnings are unchanged).masterfor:triangle 0 0,triangle 2 1,triangle 4 2,triangle 0 0 4 0(no-solution case),triangle 3 1 4 4(no-solution case).master.🤖 Generated with Claude Code