Sunday, January 14, 2007

ZX Spectrum and Scrabble Nostalgia

I've been prompted to delve back into my teenage years by a surprising article in the February issue of PC Pro which urges us to 'Forget 3D games, says Dick Pountain, it's Scrabble that PCs really need to get to grips with.'

From an early age I had a penchant for words and numbers, their calculation and manipulation. This manifested in several ways during my time at secondary school: I became keen on Scrabble and I started teaching myself to program computers.

Like many of my generation, I owe my first steps to Sir Clive Sinclair: initially, I started with a Sinclair ZX81, which my parents kindly bought for me for Christmas. With 1K of RAM, I was limited in what I could develop, though I was able to validate UK VAT registration numbers! Nevertheless, it was enough to introduce me to a new world and I could write my first programs - in Sinclair's implementation of BASIC. Within a year, there was another breakthrough with the ZX Spectrum and soon after I persuaded my parents again to invest in this new toy that boasted 16K RAM, 16 colours, sound and a wider range of software titles.

I then made a concerted effort to produce a Scrabble program, where the computer could act as one of the players. Whereas previously I had been content to write everything in BASIC, in this instance, I learnt sufficient Z80 machine code to be able to convert the main 'thinking' algorithms. Result: the computer responded in a few seconds rather than a couple of minutes!

It can be quite a work of art to cram as much as you can into the 16K. The computer had a 500 word vocabulary and included an algorithm for ensuring it played the highest scoring move, but generally it wasn't a strong opponent. In actuality, 7K was devoted to the screen display, which can be set as part of the procedure to load the program. Normally, that leaves you with just 9K, but I allotted this space to display a detailed logo in one section and a simple blocky 'Welcome' title in another, which 'hid' about 2K of instructions, which could be read as a scrolling message along the bottom of the screen. Once the game had started, though, the who screen display was refreshed, so these instructions could not be revisited unless the game was reloaded.

Having played Scrabble competitively, I wanted to see the development of a version that was much more competitive. After a while, there was a highly polished product, Psion Scrabble. I wrote to them in the beginning of '86 and described tactics that could enhance the software. Three months later I received a kind response thanking me for the ideas and wishing me well in my 'A' levels, but the overall message was that Psion was going to concentrate on the development of its hardware products. (Perhaps I should have bought some shares?!)

I stopped development of the code around that time, but retained some interest in how tactics could be encoded. About 10 years later, I happened to come across a journal article by Steven Gordon concerning Scrabble algorithms. I corresponded a little by email and learnt that he had implemented a number of similar ideas, but I think far more systematically! So he's probably a good contact for Mr. Pountain.

Over 20 years later...

I've come across an old cassette tape with a copy of the program on it and having invested in an external sound card to digitise these tapes , I decided to undertake a conversion. After some fiddling, I worked out the right settings and the process works fine - the Creative Player is able to sample at the right frequency and bits and I used MakeTZX to convert into a tape archive format.

If you're curious in seeing the program (and don't have high expectations!) you are welcome to download a copy, available as a zip package. When you've unzipped the package, you will see a number of files, with a readme and instructions. Look through those and then launch the .tzx file in an emulator — I've found emuZwin works very well on a PC.

3 comments:

Anonymous said...

I came across your blog this morning after Funkitron's Scrabble program just beat me with a score of 529. I then searched Google for entries relating to Scrabble programs to see how. I am much impressed with your ability to have programmed a Sinclair to play Scrabble (I had a ZX80, followed by a Spectrum and bought Psion's Scrabble program - it took a good 5 minutes to load!)

My quest this morning is to try to determine whether the Funkitron program actually plays fairly. I have a sneaking suspicion that its letter allocation algorithm is not entirely random. However that might just because I get beaten regularly.

Posted by Steve Ritter; 4th February

Paul Trafford said...

Steve,

Many thanks for your comments. I don't think my parents or I could afford the ZX80 for Christmas, so I had to wait a year for the ZX81 to arrive at a £30 discount ;-)

As I recall, the Psion program on its highest level was reasonably strong, quite capable of scoring 400+. In that letter I received from Psion, I was told that they could have increased the compression levels on their word list to increase its vocabulary, so it would have been stronger (but probably slower too). However, one of my comments was that the program didn't appear to keep a balanced rack, which is essential to get scores [in open games] of 500+.

I think programs have advanced considerably in this regard, so together with storing every allowable word, it doesn't surprise me if after changing its letters it often comes out with a bingo. I confess I haven't played much Scrabble for a loong time, so I'm not familiar Funkitron. Perhaps if you want to beat it, you should try for a closed game?

My program took a long time to write, sustained by the ongoing challenge, a lot of which was concerned with ways to squeeze everything into a 16K machine, though later I upgraded to 48K and must have tweaked it as the version I've converted appears to be a little over 16K.

- Paul

Paul Trafford said...

[query posted here about meditation centre in Prachuab, Thailand has been moved to another post on 'Magha Puja, World PEC and other lights of peace']