Smart Forager: reinforcement learning in GAMA
This tutorial uses a foraging model to introduce reinforcement learning in three stages. The first uses tabular Q-learning implemented in GAML. The second connects a continuous GAMA model to Python through Gymnasium and trains a PPO policy. The third extends the model to cooperative multi-agent learning with PettingZoo.
Part 1 can be followed with GAMA alone. Parts 2 and 3 use external Python packages and a GAMA server. Check the current requirements for GAMA-Gymnasium and GAMA-PettingZoo before installing them.
Part 1: Tabular Q-learning in GAML​
Build a grid world, add a forager, define rewards and episode resets, then implement a Q-table and Q-learning policy. The final step adds training metrics, a learned-value heatmap and a test mode.
Each step in this part ends with a complete model for that stage. The listing repeats the previous step and adds the new behavior, so it can be used without assembling code from earlier pages.
- The grid world
- The forager agent
- Rewards and episodes
- The Q-table
- The Q-learning algorithm
- Training charts and test mode

The model's grid heatmap and reward and epsilon charts during training.
Part 2: Continuous forager with Gymnasium​
Replace the grid with a continuous world and connect it to Python using the gama-gymnasium bridge. The steps define the bridge, sensors, movement and rewards, then train and test a PPO policy.
- Introduction and continuous world
- The GymAgent bridge
- Sensors, movement and rewards
- Headless training with PPO
- Evaluating the trained policy
Part 3: Cooperative foragers with PettingZoo​
Extend the continuous model to multiple foragers with a shared policy. The final step applies that policy to a larger group.