Debugging the Tiny BASIC Games
Thursday, 15th August 2019
I finally got around to downloading an existing Tiny BASIC interpreter. Tom Pittman rewrote his Tiny BASIC interpreter in C for 21st century enthusiasts. This single C source file should compile on just about any operating system, and is a nice little no-frills no-nonsense implementation.
Though Pittman's Tiny BASIC has some extensions (REM lines, and some rudimentary PRINT output formatting), it should run programs for the original Tiny BASIC specification without change. It needs line numbers, but the AWK Script I wrote yesterday can add those in for me.
So, do my games work? So far, I've only implemented the simplest, Hunt the Hurkle. The results aren't perfect, but are better than I expected. So far I've encountered two problems, both with the random number generator. The first one I have fixed already.
When writing the random number generator I forgot that it would return negative numbers as well as positive. So the Hurkle would sometimes appear at negative coordinates. This I fixed with the addition of the following line to the random number subroutine, just before the RETURN:
IF R<0 THEN LET R=-R
The second problem will need more investigation. The random number generator is, to put it simply, rubbish. I've tried several seeds, and so far the hurkle is always directly in one of the 8 compass directions of 5,5. I've found it in positions like 3,3, at 5,1, at 7,5 and at 1,1.
I adopted the simplest random number generator I could find that used only the four basic arithmetic operators. I can't now remember where it came from. It specified the properties of the constants that should be adopted, though the constants it used as an example were all outside the 16-bit range that Tiny BASIC allows. So I supplied my own constants, and it looks like these will need to be tweaked.
Either that or I need to find or devise an alternative pseudo-random number generator. I'll start by writing a little testbed program to generate a list of, say, 10 numbers, and then tweaking the constants to see if I can get it to generate a sequence without any obvious patterns. Once done, I'll post revised listings in future posts.