Gnoga series on Alire

After many a hurdle during Alire registration process, you now have the following at your disposal.
The main Gnoga framework for cross platform GUIs for Ada comes in version 2.2.3.
And now the Gnoga series are finally on Alire:
Gnoga_demo Demonstration programs for Gnoga
Gnoga_test Test suite of Gnoga
Gnoga_tools Tools for Gnoga
Gnoga_tuto Tutorial programs for Gnoga

Find a Gallery of demonstration, tutorials programs and more with the list of the main Gnoga components used by each program. May be helpful for a new comer or a help for finding a specific Gnoga widget example.

gnoga-list: Subscribe | Archive | Search — discussion of Gnoga or create a ticket.

6 Likes

Just finished my first vibe-coding exercise in Ada/Gnoga - classical game of Nibbles. Good to know Claude is well aware of both Ada and Gnoga, and how to compile them under Alire. The chat about compilation issues was much longer than the “programming” (which took just two short prompts).

The idea to test was whether a vibe-coded Ada code draft could be of any use for further polishing and finalizing. And, yes, it sure is.

3 Likes

I still look at Gnoga with amazement. It was such a timely integration with HTML 5

I’m not familiar using AI for Ada coding.
I’m very curious to know whether easy or hard to get started.
Have post how to do it?
Otherwise, could you post the detailed method for doing it?
Thanks in advance.

You just need an account for Claude (or ChatGPT). You may start with a free one in a browser to try. Then go to Claude Code, and select a model to use (I used Sonnet 5.5 with Medium effort).

And then just type a prompt of what do you want. Here is my initial prompt and the reply from Claude (that’s where the majority of work was done):

I need to write a game of classic nibbles, which needs to be run in a browser. The game must be written in Ada, with GUI also in Ada. Use AWS and GNOGA, or any other packages as you see fit.

I wrote Nibbles in Ada, with GNOGA doing the GUI, but I haven’t compiled or run it. This machine has no Ada toolchain (gnat, gprbuild and alr are all missing). I wrote the GNOGA calls from memory, so the first build may need small fixes. The likeliest trouble spots are the Rectangle_Type aggregate and the drawing-context calls.

Files

  • src/nibbles-game.ad[sb] holds the game rules and has no GUI code: 48×32 grid, snake, numbered food, walls, lives and levels.
  • src/nibbles-ui.ad[sb] is the GNOGA part. It draws the game on an HTML canvas, reads the keyboard through a protected object, and runs the game in its own task.
  • src/main.adb, nibbles.gpr and alire.toml are the entry point and the build files, with a dependency on the gnoga crate.
  • README.md has the build steps.

Gameplay

  • Eat the numbers 1 to 9 in order. Eating number N scores N × 10 × level and grows the snake by 3 × N segments.
  • You start with 5 lives. Hitting a wall or yourself costs one life, and eating the 9 clears the level.
  • Five wall layouts cycle, and the game speeds up each level.
  • Controls are arrows or WASD to steer, Space or Enter to start or continue, and P to pause.

To run it

  1. Install Alire.
  2. Run alr build, then bin\main.exe, which serves the game at http://localhost:8080.
  3. If the page is blank, GNOGA’s html/ and js/ folders need to be in the working directory. The README has a one-line copy command for that.

If you paste any compiler errors back to me, I’ll fix them.


And that’s pretty much it - from this point you just talk to the model, sending her error messages during the compilation. She’ll offer fixes; sometimes she’ll do it directly in your working directory for the code. For example:

Where to find the needed HTML and JS folders? They are not in the crate.

They aren’t in the crate’s top level. They’re inside Gnoga’s project template, in the Alire cache at:

D:\temp\alrcache\releases\gnoga_2.2.2_2513b058\templates\gnoga_make\singleton\

That template is for single-window apps like ours, so it has the html\ and js\ folders a singleton app needs. I copied both into your project:

  • D:\IMAGES\ADA\nibbles\html\ has boot.html, favicon.ico and robots.txt.
  • D:\IMAGES\ADA\nibbles\js\ has boot.js and jquery.min.js.

Gnoga looks for these folders next to the exe’s parent folder when the exe is in bin\. Your exe at bin\main.exe will therefore find them in the project root with no extra setup.

The README’s long xcopy command pointed at the wrong place, so ignore it. I haven’t compiled or run anything, so the game itself is still unchecked. Next, run:

alr build
bin\main.exe

It should open http://localhost:8080 in your browser. If the build still shows errors, paste them.


That’s been the last message, after which the game finally worked. From this moment I could either edit the code myself, or continue with the model asking her for the desired changes.

Hope this helps.

You need a model, an environment and a process.

  1. The models: Models are no longer as decisive in performance as they were a year ago. Open source models do the job very well, and “flash” models (Gemini, GPT, all the Chinese models) show astonishing performance on software engineering benchmarks. (I use GLM 5.3 Flash, and it works very well.)

  2. The dev environment: Claude Code is very good, but it’s not the only candidate. See OpenCode, pi, etc., plus all the other offerings from OpenAI and the major model providers. There are dozens of options available under VS Code. I use Mistral Vibe — it’s simple and works well.

  3. The process: Here too, there’s an abundance of material online, and everyone should pick what suits them best. SPARK and Ada skills are available on AdaCore’s GitHub.
    A simple approach might be to adopt an existing simple process and shape it to your own hand.

    Mine is public: GitHub - LionelDraghi/ada-project-template: Shared reference repository for Lionel's Ada projects: agent instructions template, common release procedure, locally-owned skills · GitHub

On the ‘performance’ of AI, I had this funny experience these days.

Disclaimer: I’m not a programmer, it’s just a hobby for me.

I wanted to translate a really simple gtk4 skeleton application from C to Ada with gtkada4 (taken from the C gtk4 tutorial).

After a lot of guessing and headaches (the documentation of gtkada is quite… well…), I ended with 3 small packages of maximum 10 lines each with derivations of gtk_application and gtk_application_window. The program compiled and ran without error messages. But the window was just flashing and the program ending immediatly (with success return code).

As I was getting tired of trial and error, I submitted the code and the observed behavior to different LLM to have a clue of the problem. They gave a lot of obviously wrong advices, but also some I couldn’t judge. So I tried…

The best they could do was suspecting my derivations and proposed to replace inheritance with composition. I tried a lot of their advices, but with the same result in the end: a flashing window and exit. I gave up.

That was yesterday.

This morning, I just realized that my code was okay and that my derivations had no problems. I just had forgotten 1 line of code: to add the gtk_application_window to the gtk_application :slight_smile:

All AI missed that.

1 Like

Maybe you can show the faulty code, so that others can try with different LLMs or we could retry in 6 month an see if the situation improved.

I don’t use versioning for toy projects so I don’t have the original code anymore. But I’m planning to keep a skeleton for gtkada4, and it’s really simple. So I’ll publish it and there would only need to remove that line to test AI again.