Wednesday, 25 August 2021

Old Maid for One Player and Computer


This week's Basic program is from Chapter 1 of "Atari Fun and Game" published by Tab Books in 1984. It's by L.M. Schreiber. I ported it to Micro Color Basic for the TRS-80 MC-10 from Atari 8-bit Basic, which presented some unique challenges. The first dozen lines of the program, for example, contained a small machine language loader for a program to relocate the native character set, so that some suit graphics could be added to the character set replacing the  % & ' and (  characters. I had to remove this part of the program. This routine was meant to help facilitate the printing of the suit characters.  The Atari character set does already contain suit characters, but they are spread throughout the character set, rather than being in order.  Schreiber used a method of symbolizing the cards as numbers with decimals for the suits:

.1 for HEARTS

.2 for CLUBS

.3 for DIAMONDS

.4 for SPADES

This allowed for certain basic calculations to be used to determine if suits matched by determining if the absolute differences between values of selected cards equaled .2.  If not, then the cards are not related by suit colour, which pairs must be in the game of Old Maid.  For some reason, the MC-10 couldn't handle subtraction of these fractions without a loss of decimal accuracy.  I'm hoping this is just some quirk in the emulator, rather than a fault of the MC-10. But just in case, I changed the calculations to involve multiplications by 10 before doing the subtractions and then looking for a difference of 2.

Since I removed the suit character routine, and the MC-10 can't modify its character set, I designed a two character Semigraphic 4 representation of the suit characters instead.  They're very schematic, but they give the impression of the suits enough for the purpose of play.  And Old Maid is often played with special card decks anyways, so I think it's okay.  The cards are presented as a character from the list A23456789TJQK, which correspond to a value from 1-13. Then a two character "suit" symbol is displayed.  The program already formatted the player's initial 24 cards in 3 row of 7 cards, plus 3 cards in a fourth row.  This all fit nicely on the MC-10s 32 character wide screen.  I think the screen mode for the Atari was some double wide character mode (half the normal 40), so it only had 20 columns to play with.  So the 3-character-wide cards (Symbol+Suit+space) allowed for these to be printed in 20 columns-- the space of the last column was not needed.  For my version I printed the cards with 4 characters each (Symbol+2 Suit chars+space), making 28 for a row, so there was some room to spare.

A bunch of special "POSTION" commands, which are unique to the Atari for moving the cursor to specific locations on the screen had to be modified to PRINT@ statements.  I also had to change PRINT CHR$(125) to CLS.  The Atari also doesn't appear to have MID$ LEFT$ and RIGHT$ for manipulating strings, but uses the method of defining strings as  2 dimensional arrays.  So this all had to fixed to use Microsoft Basic string handling methods instead.  The SOUND commands also had to be translated, but I found an Atari Basic manual to help me translate the values of notes.  Besides making such changes and fixing up some of my own typos resulting from inputting the program from a PDF scan that I found on line, the only other problem is a bug I think might have also affected the Atari version of the program too.  Line 1070 read:

1070 FORX=1TO5:FORQ=49TO1STEP-1:V=INT(RND(0)*Q):REM PICK A CARD

It was followed by the lines:
1080 C(0)=C(V):C(V)=C(Q):C(Q)=C(0):REM MOVE THE CARDS
1090 NEXTQ:NEXTX:RETURN:REM DO IT 5 TIMES

This routine was for shuffling. A FOR/NEXT loop counts down through the 49 card special deck. Then a random card is selected, ranging from position 1 to the position of the current card of the countdown.  Then the cards are "swapped" by shunting the random one to position 0 in the array moving the other from the current countdown position to that random position, and then putting the card shunted to 0 to the position of the countdown. But by not adding one to the RND number routine you actually get a value from 0 to just below the current card in the countdown. If RND produced 0 this would result in an extra card being introduced into the deck. Whatever was last shunted there would be swapped into the deck. This was clearly not ideal for the game being played properly.  So I switched it to the following:

1070 FORX=1TO5:FORQ=49TO1STEP-1:V=INT(RND(0)*Q)+1:REM PICK A CARD

It's possible that the RND function of Atari BASIC functions correctly and produces a number from 1 to the number that is multiplied by the RND function, but if so, this would be very unusual. The Atari uses the RND(1) format rather RND(0) of the TRS-80 line of computers, but unlike Commodore Basic, which also uses RND(1), I don't think Atari Basic is a Microsoft variation of Basic.

So if my bug fix affects the original program, and if as appears to be the case from my searches on the Net, there is no obvious downloadable copy of this specific program in any of the Atari repositories out there, then this might be the only properly working and playable copy of this interesting Basic type- card game from the early days of 8-bit computing.  If you want a taste of a simple child's game using "AI" for an opponent, then give it a try.

The game can be played via the following link. After you select "Play" below select the "Educational" programs item and then choose "OLDMAID" from the "Cassette" menu of the Javascript emulator and type RUN in the main window:


No comments:

Post a Comment