Commit Graph

4 Commits

Author SHA1 Message Date
Chris Proctor
e8a24ae7be Split q_learning.py into algorithm, environment glue, and a training script
q_learning.py mixed a bespoke BabySnake environment wrapper, the two
functions students implement, a training loop, and a terminal watch
routine in one file, with no tests and no single command to run
training.

- q_learning.py / q_learning_solution.py now hold only choose_action
  and update_q, with actions as an explicit parameter instead of a
  module-global, so the file has no babysnake/retro/retro_gamer
  imports at all.
- train_babysnake.py builds GameEnvironment directly from babysnake's
  pyproject metadata, trains, and watches the trained agent in one
  command: `python train_babysnake.py`. It also caps steps per
  episode, since a lucky random walk that keeps finding food can
  otherwise make an episode run unboundedly long.
- test_q_learning.py adds unittest coverage for both functions with no
  game dependency.
- questions.md adds a checkpoint instructing students to get the tests
  passing before training, and points the post-training step at
  train_babysnake.py.
2026-06-24 07:50:28 -04:00
Chris Proctor
7788e34ebd Migrate babysnake to retro_gamer's observation_function
BabySnake's tabular Q-learning exercise needs a small discrete state,
not the flattened board encoding retro_gamer normally produces. Define
get_state(game) in babysnake_env.py, returning a plain
(agent_x, agent_y, food_x, food_y) tuple, and point babysnake's
observation_function at it instead of declaring a character_set.
Disable the on-screen state overlay so it doesn't clutter the
terminal watch view.
2026-06-24 07:50:20 -04:00
Chris Proctor
3d42de7b12 Give forager an energy mechanic so episodes terminate naturally
Previously the game ran indefinitely and relied entirely on
max_turns_per_episode to end an episode. Add start/food energy values
so an episode ends on its own when energy runs out, and mention
retro-gamer plot in the lab's training log instructions.
2026-06-24 07:50:14 -04:00
Chris Proctor
42bc2e7a50 Initial commit 2026-06-22 16:14:58 -04:00