<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rashid Javed </title>
    <description>The latest articles on DEV Community by Rashid Javed  (@breakpoint).</description>
    <link>https://dev.to/breakpoint</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2145081%2F8e36c3e2-d315-4dc4-b9a1-764661c16d17.png</url>
      <title>DEV Community: Rashid Javed </title>
      <link>https://dev.to/breakpoint</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/breakpoint"/>
    <language>en</language>
    <item>
      <title>Decision Models, Snake Game, Codex and Benchmarking: Part 2</title>
      <dc:creator>Rashid Javed </dc:creator>
      <pubDate>Mon, 23 Nov 2026 11:22:32 +0000</pubDate>
      <link>https://dev.to/breakpoint/decision-models-snake-game-codex-and-benchmarking-part-2-3i11</link>
      <guid>https://dev.to/breakpoint/decision-models-snake-game-codex-and-benchmarking-part-2-3i11</guid>
      <description>&lt;p&gt;How I Used Snake to Benchmark Local and Cloud Decision Models&lt;/p&gt;

&lt;p&gt;Repo Link : &lt;a href="https://github.com/rjavedv/snake-ai" rel="noopener noreferrer"&gt;https://github.com/rjavedv/snake-ai&lt;/a&gt;&lt;br&gt;
This is the second blog in the two blog series. First blog can be found here : &lt;a href="https://dev.to/breakpoint/decision-models-snake-game-codex-and-benchmarking-part-1-hd7"&gt;https://dev.to/breakpoint/decision-models-snake-game-codex-and-benchmarking-part-1-hd7&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Why watching a few games left me with questions
&lt;/h2&gt;

&lt;p&gt;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.&lt;br&gt;
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.&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Defining a Snake benchmark in a scenario file
&lt;/h2&gt;

&lt;p&gt;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. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx2vh1p0f661d2uzl4ydh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx2vh1p0f661d2uzl4ydh.png" alt="Scenario File" width="426" height="805"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Short version of scenario file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"circuit-25"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"width"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"height"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"snake"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="mi"&gt;9&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="mi"&gt;9&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="mi"&gt;9&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"direction"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"RIGHT"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"food"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="mi"&gt;9&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="mi"&gt;14&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"food_target"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"move_limit"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2500&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;br&gt;
Well defining the scenario was only the starting step. The game has to be modified to accommodate the scenario logic. &lt;/p&gt;
&lt;h2&gt;
  
  
  3. Running the same scenario across models
&lt;/h2&gt;

&lt;p&gt;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.&lt;br&gt;
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. &lt;br&gt;
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.&lt;br&gt;
Command Template:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uv run snake-ai-benchmark &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;scenario&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; --model &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;model name&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;  --repeats &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;num&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sample1: 25 food scenario, multiple models, repeat twice against each&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uv run snake-ai-benchmark scenarios/circuit-25.json --model tev1:4b-mlx-bf16 --model clef-flash:9b-mxfp8 --repeats 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sample 2: 50 food scenario, single model, repeat thrice.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uv run snake-ai-benchmark scenarios/circuit-50.json --model clef-flash:9b-mxfp8 --repeats 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzmp08bdqaqi2qli6f6so.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzmp08bdqaqi2qli6f6so.png" alt="Benchmark Logs" width="800" height="356"&gt;&lt;/a&gt;&lt;br&gt;
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.&lt;/p&gt;
&lt;h2&gt;
  
  
  4. Turning run logs into an HTML dashboard
&lt;/h2&gt;

&lt;p&gt;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 &lt;strong&gt;BENCHMARK_DATA&lt;/strong&gt; variable with results from log files. &lt;br&gt;
We can generate the benchmark-dashboard html file using command line&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uv run snake-ai-dashboard &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;directory&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;output&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uv run snake-ai-dashboard logs/my-benchmarks --output logs/my-report.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Following are screenshots for the generated benchmark-dashboard.html (both code and render)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F91a09wmtctw7emrx4qw6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F91a09wmtctw7emrx4qw6.png" alt="HTML view of dashboard" width="800" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fir4c19koi2wk6cy31n1i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fir4c19koi2wk6cy31n1i.png" alt="Render1 of dashboard" width="799" height="528"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fib7z08vkkrwoamlx3hh4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fib7z08vkkrwoamlx3hh4.png" alt="Render2 of dashboard" width="800" height="536"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Bringing the workflow together with Tkinter
&lt;/h2&gt;

&lt;p&gt;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.&lt;br&gt;
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. &lt;br&gt;
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. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs7157lwfgflousf3tbfc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs7157lwfgflousf3tbfc.png" alt="SnakeGui Basic" width="800" height="692"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl6thy62d2793e7lb5hw0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl6thy62d2793e7lb5hw0.png" alt="SnakeGui Replay" width="799" height="206"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4g38y3iizd1ra0zn05rj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4g38y3iizd1ra0zn05rj.png" alt="SnakeGui Benchmark tab" width="800" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;1: Choose scenario file&lt;br&gt;
2: Choose a model to benchmark. You can benchmark multiple models too.&lt;br&gt;
3: Number of times a scenario has to be repeated&lt;br&gt;
4: Folder to store benchmark log files.&lt;br&gt;
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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdoo6ztpc0y8xtg4b99j2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdoo6ztpc0y8xtg4b99j2.png" alt="SnakeGui DashboardTab" width="800" height="469"&gt;&lt;/a&gt;&lt;br&gt;
1: Benchmark log files folder&lt;br&gt;
2: HTML Output file folder&lt;br&gt;
3: Press this button to generate the html output file&lt;br&gt;
4: The generated file is shown as a link. Clicking on it will launch it with the default browser.&lt;/p&gt;

&lt;p&gt;Overall this GUI makes it quite easy to control different parts of the gameplay and benchmarking.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Conclusion
&lt;/h2&gt;

&lt;p&gt;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 &lt;br&gt;
pygame : to render game board and perform game play&lt;br&gt;
requests : to manage API calls to decision models. &lt;br&gt;
python-dotenv : required for .env file which is used to keep openrouter api key.&lt;/p&gt;

&lt;p&gt;Please let me know your feedback, suggestions, and critique with reference to this project. &lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>vibecoding</category>
    </item>
    <item>
      <title>Decision Models, Snake Game, Codex and Benchmarking: Part 1</title>
      <dc:creator>Rashid Javed </dc:creator>
      <pubDate>Mon, 23 Nov 2026 11:17:09 +0000</pubDate>
      <link>https://dev.to/breakpoint/decision-models-snake-game-codex-and-benchmarking-part-1-hd7</link>
      <guid>https://dev.to/breakpoint/decision-models-snake-game-codex-and-benchmarking-part-1-hd7</guid>
      <description>&lt;h1&gt;
  
  
  Blog 1 of 2: I Built Snake with Codex to See How AI Decision Models Play
&lt;/h1&gt;

&lt;p&gt;Repo Link: &lt;a href="https://github.com/rjavedv/snake-ai" rel="noopener noreferrer"&gt;https://github.com/rjavedv/snake-ai&lt;/a&gt;&lt;br&gt;
This is the first blog in the two blog series. &lt;/p&gt;

&lt;h2&gt;
  
  
  1. How the idea started
&lt;/h2&gt;

&lt;p&gt;Well it was some weeks ago or some months ago, my youtube timeline just exploded with Videos about “System One Models and Jev” from TypeSafe AI. And as usual, the hype trend generated many amazing headlines like ‘Is it the end for Claude’ and the Model to end all other models etc….  I watched some videos, went to the TypeSafeAI webpage (&lt;a href="https://typesafe.ai/blog/introducing-system-one-models-and-jev)and" rel="noopener noreferrer"&gt;https://typesafe.ai/blog/introducing-system-one-models-and-jev)and&lt;/a&gt; saw the Doom demo that was using JEV for game play and making ten decisions a second. Wow! That was some speed. &lt;/p&gt;

&lt;p&gt;That got me very excited and naturally I tried to get the API key to try some stuff for myself.  Unfortunately, at that time it was hard to get the API key for Jev, i think the sign up was invitation only or a waitlist.  So with no chance to get an API key, I quickly lost interest but I still couldn't forget that Doom demo.  &lt;/p&gt;

&lt;p&gt;And as the trend is, within days we have many open source decision models on Hugging Face and GitHub, most claiming to be Jev killer :-). &lt;br&gt;
So this got me thinking if i can have a game that can be played by these decision models, would be wonderful. Although the Doom demo was very tempting to try, I wanted something simple to start with. &lt;/p&gt;

&lt;p&gt;My first thought was to try TicTacToe but it was kinda static, i mean not much movement in terms of gameplay. So my second thought was to try a snake game. It is quite visual (a snake or a line running around, consuming food tiles) and comparatively simple to develop. &lt;/p&gt;

&lt;h2&gt;
  
  
  2. Building the first playable version with Codex
&lt;/h2&gt;

&lt;p&gt;Game design for a human player was quite clear (in my head), what I was not clear was how to involve a decision model in game play. What should I send to model, what am I supposed to get back and how to map that to the game render loop. This is where I decided to use Codex as my development partner. &lt;/p&gt;

&lt;p&gt;My first prompt was quite wayward. I generally use Python so I already created a project and a virtual environment inside a folder. I created a new project in codex with reference to this folder and then asked it to create a snake using pygame. For AI gameplay, my prompt was like the following&lt;br&gt;
&lt;em&gt;The game you will design and develop will have two modes. One mode for human use where a human can play the game using arrow keys. Other game mode will be for AI where we want AI to play this game. For this purpose &lt;br&gt;
1: AI Models: we have Ollama on this machine with a decision model downloaded on this machine as following. Documentation and sample usage url is also given with the model and you can check the sample code on the url.&lt;br&gt;
Model Name: kev:27b-nvfp4&lt;br&gt;
Documentation: &lt;a href="https://ollama.com/library/kev" rel="noopener noreferrer"&gt;https://ollama.com/library/kev&lt;/a&gt;&lt;br&gt;
2: In the AI mode, the game should pass a state object to the AI model which describes the snake position, food positions, and wall positions. System should ask the AI that based on the given game state, which arrow key should be pressed (highest or most likely probability)&lt;br&gt;
3: Based on this input, the selected arrow key code should be passed to game to simulate the key press. Based on the arrow key, the game should move to a new state where the snake would have moved to a new location based on the arrow key. this state should again pass to AI, asking for the next decision. &lt;br&gt;
You should start with a plan phase. Ask me questions if any further information is needed. Once all the required information is provided, proceed to develop the Game in python. Log all requests and responses to a decision model in a log file using json format.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;As expected, Codex did ask me a few questions and created what I wanted. Since I want to keep things simple, I used a .env file to store the Ollama local url and the local model to use. So in the main game window, we have very simple key controls to navigate. Pressing H key will start a game for human player while pressing A will start the AI game play. Esc key will cause the game to quit. &lt;/p&gt;

&lt;p&gt;For the AI gameplay, the games initially read .env (i later changed it to a .config file) to read the Ollama local url and the model name to run. &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4ceis27qvl219vyeo2o7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4ceis27qvl219vyeo2o7.png" alt="Main Game Window" width="719" height="699"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All of this is implemented in three files. &lt;br&gt;
engine.py is about game defaults and game rules.&lt;br&gt;
app.py is where the actual game rendering happens using pygame. &lt;br&gt;
ai.py is where all requests/response cycles to decision model happens. &lt;/p&gt;

&lt;h2&gt;
  
  
  3. Handing the arrow keys to a decision model
&lt;/h2&gt;

&lt;p&gt;This is where I really appreciate Codex. It came up with a pretty solid request/response structure for AI gameplay. Later on, I tweak the prompt that is sent to the decision model to make it more clear. &lt;/p&gt;

&lt;p&gt;The idea is to send the game board and snake data to the Decision model along with food coordinates. We tell the decision model to avoid walls and snake body and move towards the food. In its core it's a choice question where we present the above information along with direction keys to the decision model. The model then returns the choice dictionary with direction key and probability. Obviously the direction key with highest probability is what the model is suggesting as the next move. All these requests and responses were logged in a logfile for later review. &lt;/p&gt;

&lt;p&gt;One interesting thing here is that initially we were asking the model to choose from all four direction keys. Strange enough we do get the response that is totally in the opposite direction, like the snake is moving downwards and the model returned UP as the most likely choice. Which might be logically correct but not possible in game context. As in the Snake game, you cannot move opposite to your movement direction. So the request format was adjusted to ask the model to choose from three possible directions instead of four. This improved the gameplay a little bit. &lt;/p&gt;

&lt;p&gt;Now the issue with log files was that they were just files. I mean I tried reading files to understand how a model is playing the game but it gets hard to visualize gameplay from just numbers.&lt;/p&gt;

&lt;p&gt;In the screenshot below, we can see a request and response from the log file. There are some additional ‘event types’ are also put in log file for example ‘session_start’ holds information about model, game speed, initial state of snake, food, score and steps. Similarly we have an event type ‘transition’ that shows the board state after we have acted upon ‘response’ showing the snake new state and which key was selected.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fejs88f8e85864ujvbuks.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fejs88f8e85864ujvbuks.png" alt="Log file View" width="799" height="297"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Building the log viewer to see what happened
&lt;/h2&gt;

&lt;p&gt;As apparent from the above screenshot of the log file, it was hard to visualize what was going on with the game. To solve this issue, I prompted Codex to build a log viewer where we can ‘play’ a log file on game board using up and down arrow keys. These two keys are used to move to different rows in log file. &lt;/p&gt;

&lt;p&gt;As per the prompt, Codex generated a solution where the game window was shown on the left and log file was shown on the right side of screen. User can use up/down arrow keys to navigate the log file and the ‘current’ row is then rendered on game screen. Game window was pygame window while file preview window was rendered using tkinter.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fklfzgap6nk0atnso7tpx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fklfzgap6nk0atnso7tpx.png" alt="Log File Visualize" width="799" height="497"&gt;&lt;/a&gt;&lt;br&gt;
Refer to the above screenshot, following are the key areas for this log file viewer&lt;br&gt;
1: Name of the log file currently being viewed&lt;br&gt;
2: Current row number of the log file &lt;br&gt;
3: Row and Column numbers were added to help in visualize the log file entries.&lt;br&gt;
4: Snake as list of coordinates. &lt;br&gt;
5: Food Location&lt;br&gt;
All of the replay logic is held in replay.py file&lt;/p&gt;

&lt;h2&gt;
  
  
  5. OpenRouter joins the party
&lt;/h2&gt;

&lt;p&gt;While I was enjoying the snake game playing with various Ollama decision models, I found out the Jev is available on OpenRouter. So I quickly went there to verify and yes, it was there along with several other decision models. That was indeed wonderful. &lt;/p&gt;

&lt;p&gt;Now the question was how to change my existing snake game. Luckily the API was the same as used with Ollama decision models. Only difference with OpenRouter was that you have to send OpenRouter API key in ‘Authorization’ request header.&lt;/p&gt;

&lt;p&gt;It was at this point that I restructured the .config file. Added an AI_PRIVODER option with possible values as ‘ollama’ or openrouter’. Local AI Model Name and Ollama base URL were already there in config, I just added OpenRouter Model Name and OpenRouter base URL. For these changes, few adjustments were made in ai.py file. &lt;/p&gt;

&lt;h2&gt;
  
  
  6. So it was working fine or was it ….
&lt;/h2&gt;

&lt;p&gt;So by now we had a snake game that you can play as human or use different Decision models to play it. Record the AI progress in log file and then replay the log file on the game board. It was at this point that I realized I do not have a way to compare two different decision models. Since Food appears randomly, we cannot judge properly how Model A performed against Model B. &lt;br&gt;
This is where the idea of benchmarking started. This is discussed in my second blog : &lt;a href="https://dev.to/breakpoint/decision-models-snake-game-codex-and-benchmarking-part-2-3i11"&gt;https://dev.to/breakpoint/decision-models-snake-game-codex-and-benchmarking-part-2-3i11&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>vibecoding</category>
    </item>
    <item>
      <title>Story of a Wordle Solver</title>
      <dc:creator>Rashid Javed </dc:creator>
      <pubDate>Sat, 01 Feb 2025 18:26:06 +0000</pubDate>
      <link>https://dev.to/breakpoint/story-of-a-wordle-solver-529m</link>
      <guid>https://dev.to/breakpoint/story-of-a-wordle-solver-529m</guid>
      <description>&lt;p&gt;&lt;em&gt;Hurry up, what's a five-letter word with 'i', 'c', 'e' as second, third and fourth letters!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The question brought me back from my YouTube video spree. It was my wife with her phone in hand, again on wordle&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I, ummm, not sure, what can it be.... may be Ricer, Dicer. &lt;br&gt;
No, it cannot contain an 'r. &lt;br&gt;
well i honestly don't know.&lt;br&gt;
You always say that. You don't care about me.&lt;br&gt;
Me:  I .... WHAT ???&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;These exchanges were becoming daily routine and something need to be done to fix it. Initially i thought to use some LLM like ChatGPT or Google Gemini to solve this issue. However, after few hit and try efforts, it was clear that those things run on prompts and for problems like these, accurate prompts are very important.&lt;/p&gt;

&lt;p&gt;Thinking about it, i had that light bulb moment. Why cannot i make a space on hugging face. use some available text generation model and see how it goes. &lt;/p&gt;

&lt;p&gt;Ok, keep thinking.&lt;/p&gt;

&lt;p&gt;Yeah, to avoid typing prompt, i will do it in background. So, on frontend user can input the word and the characters state (it can be either &lt;br&gt;
Grey-This character is not in the chosen word. &lt;br&gt;
Yellow-This character is part of chosen word but right now it is at wrong position. &lt;br&gt;
Green-This character is part of chosen word and is at right position). &lt;br&gt;
Then, i can form a prompt using the user provided data and pass it to text generation model. May be add a system prompt to ensure that output is just the required words keeping the output short and simple.&lt;/p&gt;

&lt;p&gt;Well, it didn't worked. like sometimes even for same prompt, i was getting different output.&lt;/p&gt;

&lt;p&gt;What to do now??? Another light bulb moment! Why can't this be a word list problem. Have a list of words, based on user input, keep removing words until we are left with the final answer.&lt;/p&gt;

&lt;p&gt;May be it will work. Where to get the word list. Spending some time on google landed me on this amazing github word repo&lt;br&gt;
&lt;a href="https://github.com/dwyl/english-wordsurl" rel="noopener noreferrer"&gt;dwyl / english-words&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I quickly extracted all the five letter words form the list and started thinking about the solution. So like before, we will get a word from user and its characters status. Based on that we can reduce the list.&lt;br&gt;
pretty straight forward logic....&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Grey - Remove all words from the list that contains any grey character because anyway the chosen word will not contain these characters at any position.&lt;/li&gt;
&lt;li&gt;Green - Only keep those words in list which has same character at same position. Remove all other words. for example if we get a green 'e' at fifth position, we can remove all those words from list which do not contain 'e' at fifth position.&lt;/li&gt;
&lt;li&gt;Yellow - Hmm, these are tricky. But let's keep on reducing list. so, if first character is 'r' and is yellow, it means we can safely remove all words from list that has 'r' as first character. Because yellow means this character is part of chosen word but not at the current position.
Ok, that was quick. lets build it in Streamlit as anyways i was using Python for my hobby projects and had tried little bit of Flask but Streamlit output looks so cool. I have watched some demos and was impressed with its widgets and responsiveness. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Well, after sending a lot of time going through the Streamlit documentation, I was able to put together some sort of working web page. Too bad it looks different on mobile screen. I thought it was looking good on desktop. Anyways, it is kind of working, you can try the app here&lt;br&gt;
&lt;a href="https://stwordl-rjv.streamlit.app/" rel="noopener noreferrer"&gt;Wordle Helper on Streamlit Community cloud&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;For source code and a basic help document, you can refer to the GitHub repo. &lt;br&gt;
&lt;a href="https://github.com/rjavedv/st_wordl" rel="noopener noreferrer"&gt;GitHub Repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are here, then Thanks for reading the complete blog :-). Please try the app and let me know your comments. &lt;br&gt;
Happy coding!&lt;/p&gt;

</description>
      <category>python</category>
      <category>fun</category>
      <category>streamlit</category>
    </item>
  </channel>
</rss>
