Atomis Development Blog

Black Forest Games: Scoring a Garden Championship in BASIC

Every summer there is a championship in the garden. Kubb, a wheelbarrow sprint, boule, and something with a saw at the end. And every summer the same thing happens. Someone writes the points on a sheet of paper, the sheet gets wet, and by the third game nobody trusts the total any more.

So this year the paper is gone. 651 lines of jdBasic, one file, and a scoreboard on the TV that is always right.

Four tabs and a screen everyone can read

The Black Forest Games dashboard: three dropdowns to record a result, and the live standings table below with points and a certificate button per row

The whole event runs from this one screen. Pick the game, pick the person, pick the place, hit Record. The standings above re-sort while you let go of the mouse. Three clicks per placement, nine per game, and then you go back outside.

The rest of the app is setup you do the evening before. A Settings tab for the event name and date, a Participants tab, a Games tab. F11 makes it fullscreen, because the whole point is that it runs on the big screen where everybody can see it.

Recorded the wrong name? Every result has a Delete button. There is no undo stack and no cache to invalidate, because nothing is stored twice.

The standings are a query, not a variable

No score is ever kept in a variable. The standings are one SQL statement that joins the results onto the games, turns a place into points with a CASE, and sums it up.

SELECT t.nr, t.name, t.title,
       COALESCE(SUM(CASE r.place WHEN 1 THEN g.p1
                                 WHEN 2 THEN g.p2
                                 WHEN 3 THEN g.p3
                                 ELSE 0 END), 0) AS pts
FROM participants t
LEFT JOIN results r ON r.part_id = t.id
LEFT JOIN games g  ON g.id = r.game_id
GROUP BY t.id
ORDER BY pts DESC, t.name ASC

That runs every frame. Sixty times a second, on a laptop, for six people and four games, and it costs nothing you could measure. It also means a deleted result cannot leave a wrong number behind. There is no number to leave behind.

Points belong to the game, not to the app

The Games tab: four disciplines with their point values, the Log Sawing Final at 6, 4 and 2 points

Every game carries its own three numbers. Default is 3 / 2 / 1 and most games keep it. The finale is 6 / 4 / 2, and that is the part that makes the afternoon work. Somebody who is four points behind after three games is still in it, and everybody knows it, so nobody wanders off.

A PDF with no PDF library

The generated certificate: navy double frame, CERTIFICATE in Helvetica-Bold, event name and date, the winner's name and title, and a gold medal with the number 1

Press Certificate next to a name and a PDF lands next to the script. 1309 bytes. Five objects, a cross-reference table, and a byte offset for each one, assembled in jdBasic and written out as text.

Two things you find out fast when you write a PDF by hand.

Centring text needs the font metrics. There is no measure call, so the file carries the Helvetica-Bold advance widths for the printable WinAnsi range as a string of numbers, and the width of a line is the sum of its characters. Then the x position is the page centre minus half of that.

And PDF has no circle. The gold medal is four Bezier curves with the control points at 0.5523 times the radius, which is the constant that turns four arcs into something the eye reads as round.

Places one, two and three get gold, silver and bronze. Below that everybody gets bronze, because at a garden championship every single person gets a certificate and nobody counts the colours.

Run it for your own event

The screenshots above are a made-up event, but the app is real and the whole thing is two files. Everything is stored in one SQLite database next to the script, so backing up your event is copying one file, and starting a new one is deleting it.

There is a step by step README that assumes nothing. Download the Vibe-Game Pack from the releases page, unzip it, drop the two files into a folder next to the exe, double-click. Nothing gets installed. The rest of the page is what to type the evening before and what to click during the event. If you have a sports day, a company summer party or a club tournament coming up, that is all you need.

Source under jdb/demos/bfwm in the jdBasic repo, and the language itself at jdbasic.org.

The saw wins it every year anyway.

← Back to all posts