Fix: live games never spawn food after turn 0#130
Merged
Conversation
The live game loop (game_runner -> apply_turn) never called rules::food::maybe_spawn_food -- it was only wired into the run_game_with_random_moves simulation helper. Live games advertised food_spawn_chance=15 / minimum_food=1 on the wire but no food ever spawned after the initial board (confirmed in prod: game 54be71a6 had 5 food at turn 0 and zero from ~turn 30 onward). Add engine::spawn_food, called by the game runner after each turn and before the frame is recorded so the viewer and the snakes' next /move requests both see the new food. Constrictor games (in-flight PR #128) never spawn food, so the helper is mode-aware from the start. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
coreyja
approved these changes
Jul 15, 2026
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.
The bug
Live games advertise
food_spawn_chance: 15/minimum_food: 1on the wire, butrules::food::maybe_spawn_foodwas only called in therun_game_with_random_movessimulation helper — never in the production path (game_runner→engine::apply_turn). Once the initial 5 food were eaten, no food ever spawned again.Confirmed in prod: game
54be71a6-f06e-402c-b4a9-01e5b3bc5ddb(Standard 11x11 ranked) — 5 food at turn 0, zero food from ~turn 30 through game end at turn ~114.This shortens/starves out every ranked game and diverges from the Go engine, which spawns food between turns. Worth landing before the launch announcement.
The fix
New
engine::spawn_food(game)helper, called by the game runner after each turn and before the frame is recorded, so the viewer and the snakes' next/moverequests both see the new food. It's mode-aware from the start: constrictor games (in-flight #128) never spawn food; all other modes use the standard settings.Deliberately does not touch the
run_game_with_random_movesinline spawn or the dispatch matches, so it merges cleanly alongside #128 and #129 — I'll unify the inline call into the helper when rebasing whichever of those lands last.Tests
test_spawn_food_standard_respects_minimum_food— empty board respawns up tominimum_foodtest_spawn_food_constrictor_never_spawns— 100 iterations, guard holds🤖 Generated with Claude Code