fix: standardize home-run detection to use batter_final only (#22) #68
No reviewers
Labels
No Label
ai-changes-requested
ai-failed
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
ai-working
bug
enhancement
feature
in-queue
performance
security
tech-debt
todo
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-discord#68
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/paper-dynasty-discord-22"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
batter_final == 4 or batter_to_base == 4atdb_calls_gameplay.py:1291batter_finalfrombatter_to_basebefore the check, making the_on_finalfield the single source of truth# patch to handle little league home runs TODO:comment that flagged the inconsistencyRoot Cause
advance_runners(num_bases=4)setsbatter_final = 4in the DB, but some code paths (e.g. inside-the-park / "little league" HRs) calledcomplete_play(batter_to_base=4)withoutbatter_finalbeing set first. The old check worked around this withor batter_to_base == 4. The fix normalisesbatter_finalat the top of the check block instead.Files Changed
db_calls_gameplay.py— 3-line functional change atcomplete_play()(~line 1452); rest of diff is ruff auto-formatting applied by the project's configured Edit hook (same pattern as PRs #60–#65)Test Results
No test suite configured for this path. Change verified by code review — logic is equivalent for all callers:
batter_to_base=4→ setsbatter_final=4, check passes (HR) ✓batter_to_base=1/2/3→ setsbatter_final=1/2/3, check fails (not HR) ✓batter_to_base=None→batter_finalunchanged, check uses existing DB value ✓Other Observations
db_calls_gameplay.py:1379still assignsthis_play.batter_final = batter_to_base(now redundant). It's harmless and left untouched to keep scope minimal.AI Code Review
Files Reviewed
db_calls_gameplay.py(modified)Findings
Correctness
The 3-line functional change is correct. The normalization of
batter_finalfrombatter_to_basebefore the HR check resolves the inconsistency cleanly:batter_to_base=4→batter_final=4set early,if this_play.batter_final == 4:triggers HR ✓batter_to_base=1/2/3→batter_finalset to non-4, HR check fails ✓batter_to_base=None→ early guardif batter_to_base is not None:is False,batter_finalunchanged from DB ✓Verified all callers in
in_game/game_helpers.py,cogs/gameplay_legacy.py, anddb_calls_gameplay.py(undo_play). All passNone,1,2,3, or4— theis not Noneguard is the correct idiom for optional int parameters (vsif batter_to_base:which would incorrectly treat0as None, though0is never passed here).The redundant
this_play.batter_final = batter_to_baseat line 1379 (now double-assigns the same value) is harmless and correctly left in scope.Security
No issues found.
Style & Conventions
The functional diff matches project conventions. The remainder of the diff is ruff auto-formatting (quote normalization, line splits on chained method calls), consistent with PRs #60–#65.
Suggestions
None.
Verdict: APPROVED
Clean removal of the TODO hack. The single-source-of-truth approach is more correct and the
is not Noneguard handles theNonedefault properly. No behavioral change for any existing call site.Automated review by Claude PR Reviewer
3952813730to9b5ded1e1eClosing — will re-implement fresh against
main. Original PR had unrebaseable conflicts from the scouting refactor.Pull request closed