Decision Models, Snake Game, Codex and Benchmarking: Part 2
How I Used Snake to Benchmark Local and Cloud Decision Models Repo Link : https://github.com/rjavedv/snake-ai This is the second blog in the two blog series. First blog can be found here : https://dev.to/breakpoint/deci
How I Used Snake to Benchmark Local and Cloud Decision Models
Repo Link : https://github.com/rjavedv/snake-ai
This is the second blog in the two blog series. First blog can be found here : https://dev.to/breakpoint/decision-models-snake-game-codex-and-benchmarking-part-1-hd7.
1. Why watching a few games left me with questions
We have already discussed in Blog1, the idea behind snake game and the ability to use decision models from Ollama or OpenRouter for gameplay. However while the log was capturing all the relevant information for each request/response cycle, there was no way to conclude how good or bad a given model was.
The main issue was the random position of food. For each game, the food appears at different random locations. And while for some models, the snake seems to make an effort to move towards food, for some other models, it seems like the snake was just randomly moving on board. This got me thinking that we need to provide a level playing field to these decision models.
2. Defining a Snake benchmark in a scenario file
So the idea of scenario file was born. The scenario file was a simple json file. It defined the board height and width, Snake coordinates, snake direction and most important of all, pre-defined food locations.
Short version of scenario file:
{
"name": "circuit-25",
"version": 1,
"width": 24,
"height": 18,
"snake": [
[
12,
9
],
[
11,
9
],
[
10,
9
]
],
"direction": "RIGHT",
"food": [
[
18,
9
],
[
20,
14
]
],
"food_target": 25,
"move_limit": 2500
}
Food activates one item at a time. As of now we have 25 and 50 food scenarios. If the snake occupies the next food cell, the target waits until a move frees it. The waiting moves still count toward the limit. Collecting the target on the last allowed move counts as completion. Collisions take precedence over the move limit, and a failed model request ends the run without adding a physical move.
Each log includes the scenario, its fingerprint, the model and provider, the repeat number, the recorded decisions and moves, food milestones, and the final summary when available. Changing a scenario field produces a different fingerprint, so the dashboard separates the results even when the name and version match.
Well defining the scenario was only the starting step. The game has to be modified to accommodate the scenario logic.
3. Running the same scenario across models
Now that the scenario is defined, the remaining part was to reuse the existing game class so it can accommodate the scenario rendering. For this Codex created a new benchmark.py file and in this file a child class BenchmarkGame with reference to Game class from engine.py class.
The main idea here is to spawn food as per the scenario file instead of random spawn (as it is in the original game class). We also implement a move limit to avoid any infinite loop by decision model during benchmarking.
From the command line you can run the given scenario for one or mode models, you can also define the repeat parameters that tells the program to repeat the scenario.
Command Template:
uv run snake-ai-benchmark <scenario> --model <model name> --repeats <num>
Sample1: 25 food scenario, multiple models, repeat twice against each
uv run snake-ai-benchmark scenarios/circuit-25.json --model tev1:4b-mlx-bf16 --model clef-flash:9b-mxfp8 --repeats 2
Sample 2: 50 food scenario, single model, repeat thrice.
uv run snake-ai-benchmark scenarios/circuit-50.json --model clef-flash:9b-mxfp8 --repeats 3
All of this information is recorded in a log file. Its format is a little bit different from the original log format. Following screenshot is for benchmark log file

If you compare it to the normal log file we discussed earlier in the AI gameplay part, here we are sending several additional parameters to the benchmark category such as scenario name, allowed food positions, move limit and fingerprint.
4. Turning run logs into an HTML dashboard
In this sections, we combine the benchmarking logs into one overview page. The concept here is that we have a python file dashboard.py, it uses a template html file called dashboard.html. In dashboard.py we have a read_run function that reads a log file from the benchmark directory and formats its output in a python dictionary format. This function is then called for each log file in benchmark directory and the result is added in a list and then the whole list is converted to json format and used as an input to replace BENCHMARK_DATA variable with results from log files.
We can generate the benchmark-dashboard html file using command line
uv run snake-ai-dashboard <directory> <output>
uv run snake-ai-dashboard logs/my-benchmarks --output logs/my-report.html
Following are screenshots for the generated benchmark-dashboard.html (both code and render)
5. Bringing the workflow together with Tkinter
By now, I was pretty happy with the functionality of project. We were able to play snake game as human player, or as input to decision model. We were able to replay the log files generated by AI decision models. We were also able to run benchmarks against various decision models using pre-defined scenarios and we were also able to generate a static html dashboard from the benchmark logs to compare the results.
Only issue was that these were separate commands we need to run from the command line and we have to remember various command line options for each.
To make it all part of one coherent app, I decided to add a simple tkinter gui frontend on this project. In my prompt to Codex, I asked to keep the tkinter gui code in a separate section and ensure that no changes are made to the previous python file so that the command line part keep working as it is. Just a basic working gui frontend using builtin python tkinter library.
In the above screenshot, fields in 1 are basically read from a .config file. So we can say that .config acts are default field values here. Users can overwrite these fields as needed.the tabstrib in 2 contains various tabs relating to different part of this project. For example the active tab in this screenshot is βPlayβ and here user is provided the choice to play the game as human player or as AI decision model. User can also set game speed and play the game.
Here we can choose a log file to replay. As mentioned earlier, replay will display the game board and a window showing the log file. User can use up or down arrow key to scroll in log file.
1: Choose scenario file
2: Choose a model to benchmark. You can benchmark multiple models too.
3: Number of times a scenario has to be repeated
4: Folder to store benchmark log files.
5: Output window, this shows output from command line (as we mentioned above, benchmark was a command line utility and during benchmarking process, various status messages are output to command line/terminal window.

1: Benchmark log files folder
2: HTML Output file folder
3: Press this button to generate the html output file
4: The generated file is shown as a link. Clicking on it will launch it with the default browser.
Overall this GUI makes it quite easy to control different parts of the gameplay and benchmarking.
6. Conclusion
The project repo link is already shared at the start of the blog. Please do give it a try. I wanted to keep things simple so avoided using many additional libraries. The absolute necessary additional libraries for this project are
pygame : to render game board and perform game play
requests : to manage API calls to decision models.
python-dotenv : required for .env file which is used to keep openrouter api key.
Please let me know your feedback, suggestions, and critique with reference to this project.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.





