Skip to content

Refactor triangle.c for legibility - #1

Open
LouieVirosa wants to merge 1 commit into
masterfrom
refactor/legibility
Open

Refactor triangle.c for legibility#1
LouieVirosa wants to merge 1 commit into
masterfrom
refactor/legibility

Conversation

@LouieVirosa

Copy link
Copy Markdown
Owner

Summary

  • 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. Adding or changing a jump direction is now a one-line table edit instead of ~40 lines duplicated across two functions.
  • Extract argument parsing out of main() into parse_args().
  • Tidy up init_game() indentation, drop the trivial column_max[5] = {0,1,2,3,4} lookup in favor of using the row index directly, and introduce a BOARD_SIZE constant in triangle.h.
  • Net change in triangle.c: ~115 fewer lines despite added comments.

No behavioral change. Same DFS exploration order, same move enumeration, same output format.

Test plan

  • Builds with no new warnings (the two pre-existing %llu format warnings are unchanged).
  • Byte-identical stdout vs master for: 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).
  • Error paths (no args, row out of range, column > row) produce the same messages as master.

🤖 Generated with Claude Code

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>
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.

1 participant