[baseball] make the AI's off-plate pitches actually miss the zone - #397
Draft
gazure wants to merge 1 commit into
Draft
[baseball] make the AI's off-plate pitches actually miss the zone#397gazure wants to merge 1 commit into
gazure wants to merge 1 commit into
Conversation
`ai_pitch_plan` aims in the zone 60% of the time and "just off the plate" the rest. The off-plate branch sampled a rectangle spanning x ±1.55 by y 1.05..4.05, which fully contains the strike zone — so about a third of those intended misses finished over the plate for a called strike, putting the real in-zone rate near 73% rather than the intended 60%. That sat right on the 75% ceiling asserted by `the_ai_pitcher_throws_strikes_and_balls_in_a_sane_mix`, which failed in roughly 1 run in 4 (measured: 3/12, then 2/12). Aim past one chosen edge instead, so a pitch meant to miss always misses. Strike rate returns to ~60% and the test passed 30/30 runs. Adds `a_pitch_meant_to_miss_actually_misses` to pin the invariant directly rather than relying on the statistical band to catch it. Co-Authored-By: Claude Opus 5 <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.
Problem
the_ai_pitcher_throws_strikes_and_balls_in_a_sane_mixis flaky onmain— it failed in roughly 1 run in 4 (measured 3/12, then 2/12 across 24 runs), always by overshooting the upper bound (76–79% vs. the asserted 75% ceiling).It is not just unlucky sampling.
ai_pitch_planaims in the zone 60% of the time and "just off the plate" the rest, but the off-plate branch sampled a rectangle spanningx ±1.55byy 1.05..4.05— which fully contains the strike zone (x ±0.83,y 1.6..3.4). The zone is ~32% of that rectangle's area, so:The AI was throwing ~73% strikes when the mix intends 60%, landing right on the test's ceiling — hence a coin-flip failure rather than a clean pass or a clean fail.
Fix
Aim past one chosen edge (inside/outside/high/low) instead of sampling a rectangle around the plate, so a pitch meant to miss always misses. All four cases stay within
AIM_LIMIT_*, sothe_ai_pitcher_never_aims_somewhere_unreachablestill holds.HBP_Xis-1.75, beyondAIM_LIMIT_Xof1.7, so hit-by-pitch was never reachable by aim and is unaffected.Also adds
a_pitch_meant_to_miss_actually_misses, which pins the invariant directly rather than leaving a statistical band as the only thing standing between this bug and CI.Verification
0.45..=0.75cargo +nightly fmt --all -- --checkclean; CI clippy reports no errors🤖 Generated with Claude Code