Entries Tagged as ''

A Simple Brain Game

While User RPL is a difficult language for the unfamilar itself, entering a program via the HP 48G directly is a pain.  The earlier program I wrote, which plays music, was entered directly into the calculator as was today’s much larger program.  After writing the music player, I wanted to author something that interacted with the user and was at least mildly interesting.

I’ve been entering the code directly into the calculator simply because it immediately complains if a syntax error has occurred.  Authoring a lengthy program on a PC followed by uploading to the calculator would be tedious in my case due to my unfamiliarity with the language, which guarantees plenty of syntax errors.  There are some emulation packages and code editors available, mostly from hpcalc.org, but I’ve had almost no luck with any of them.  The editors and emulators available are somewhat older, and almost all are for Windows (I’m more-or-less strictly GNU/Linux at home).  While their being Windows application isn’t inherently problematic necessarily thanks to Wine, these older programs often ship with older, non-standard installers.  Furthermore, a lot of packages are either an editor or an emulator.  What I’d really like is an integration of the two, but I couldn’t find a suitable package.  Therefore, I’ve stuck to typing programs directly into the calculator.

My new game is much larger than the music player, and it integrates some ideas that weren’t present in the music player.  Basically, the game is a simple math game that challenges the user to solve 10 addition problems as fast as possible.  The user simply presses the appropriate number to solve the problem.  I used the WAIT statement to retreive user input.  This statement takes a single argument, which specifies the amount of time to wait for a keypress.  Because I wanted the program to wait forever, I used the input 0.  The WAIT statement, when a key is pressed, returns a very oddly coded floating point number.  The number is 2 digits, a decimal point, and a final single digit.  The first digit, in the tens location, specifies the row of the key pressed starting from 1 at the row directly below the screen and ascending as distance from the screen increases.  The second digit is the column of the key pressed.  Finally, the digit after the decimal specifies whether one of the shift keys was also pressed.  It’s a neat technique for dealing with user input, but, when programming, it was difficult to process.  Since I only wanted numbers, it was solvable using HP’s CASE structure.

My other concern was concatenating strings, especially with numbers.  After perusing some documentation, I found no functions that claimed to do anything.  On a whim, I tried adding a number to a string.  Sure enough, this technique worked like a charm!

Another fun point is that only one input per problem is necessary, but often the additive result is greater than or equal to 10.  Rather than limit the problems, I decided to check if the two random number to add are greater than or equal to 10.  If so, I set a flag on the calculator.  Flags in User RPL are basically simple booleans that are always present in memory and can be referenced by integer.  For example, to set the first flag on the calculator, I would use the code:

1 SF

The SF statements sets the flag, essentially creating a true boolean state.  To unset the flag, or clear it, the CF statement is used.  Flags can then be queried using the SF? or CF? statements.  Sixty four flags are available to the user, while another sixty four store calculator settings.  Amusingly, the settings flags are not protected in any way, allowing programs to mess with the calculator easily.  Flags seem to be an odd inclusion in User RPL, but they are quite useful.

The game is mildly amusing to play.  I’ve made a video of it, as shown below.  My wife was able to complete the game in 19 seconds, which I still haven’t beat. Some problems cause brain farts, so I occasionally have to stop and think.  A video of the game is available below:

I think some people might notice my having a bit of trouble on one of the problems.  I like to think of the game as good brain exercise, similar to those Nintendo DS Brain Age games, only simpler. The source code, which I’ve cleaned up considerably by adding indentation (the HP 48G doesn’t bother with storing unnecessary whitespace in programs) and removing special characters:

I did notice a few things when transfering the program off the calculator.  First, the Rainbow 100 apparently does contain the double angled bracket character, which shows up fine on that computer.  Also, my Ubuntu box also displayed the double brackets properly.  The reason it doesn’t display properly on PC’s generally under MS-DOS is because of IBM’s poor implementation of the ANSI X3.64 standard.  The Rainbow implements this standard properly, which specifies escape sequences and extended characters.  However, IBM really dropped the ball on this, requiring the ANSI.SYS driver to be loaded.  Even with the driver, IBM PCs did not conform to the standard.  However, as IBM PCs became the defacto personal computer standard, the non-standard became the standard.

Anyway, I hope people enjoy this little game, even if it is only via the video.  I think at this point I may move on with my RetroChallenge.