Skip to content

Fix: live games never spawn food after turn 0#130

Merged
coreyja merged 1 commit into
mainfrom
byte/fix-live-food-spawn
Jul 15, 2026
Merged

Fix: live games never spawn food after turn 0#130
coreyja merged 1 commit into
mainfrom
byte/fix-live-food-spawn

Conversation

@byte-the-bot

Copy link
Copy Markdown
Collaborator

The bug

Live games advertise food_spawn_chance: 15 / minimum_food: 1 on the wire, but rules::food::maybe_spawn_food was only called in the run_game_with_random_moves simulation helper — never in the production path (game_runnerengine::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 /move requests 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_moves inline 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 to minimum_food
  • test_spawn_food_constrictor_never_spawns — 100 iterations, guard holds
  • Full suite: 415 passed / 0 failed; clippy + fmt clean

🤖 Generated with Claude Code

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
coreyja merged commit 031c6cd into main Jul 15, 2026
6 checks passed
@coreyja
coreyja deleted the byte/fix-live-food-spawn branch July 15, 2026 11:10
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.

2 participants