Friday, 7 February 2025

"Computer Dominoes" by David Smith (1982)


I've typed in another game with an AI opponent and modified it to work on the TRS-80 Micro Color Computer ("MC-10") using Micro Color BASIC.  It's from source code in Your Computer Magazine, February 1982, and originally was for the Commodore PET.  The game plays a variation of the "All Fives" game of Dominoes.  But instead of just multiples of 5, scores are also awarded for end totals that can make multiples of 3.  A single point is awarded for each possible multiple of the two types. The computer and human player start with 9 dominoes. When a player uses up their dominoes or neither can place a domino, then a new hand of 9 is dealt. The goal is to be the first to earn a total of exactly 72.  If points are earned over this amount, they are ignored until the exact amount is achieved.

As usual, I had to chop out the Petsci text-graphic part of the program (involving lots of POKEs), and replace it with an MC-10  semi-graphic-4 character printing routine (using lots of PRINT@s).  I created a routine to lay down a string of dominoes that snakes around the screen so that all 18 possible dominoes can fit. The routine had to print horizontal and vertical dominoes, depending on their location in the string.  It also is used to list the human player's dominoes at the bottom of the screen.  The very low res. nature of the Semigraphics-4 (64X16) mode called for some compromises. The 6 dot domino looks like two solid bars instead of 3 discreate dotes for each bar and in order to differentiate between individual touching tiles, I alternate the colors of the tiles between white and yellow.  It is based on my recollections of  "mixed" sets of dominoes from my youth, which had pure white tiles and more yellowish "ivory" tiles.

Also as usual, I found what I think are some bugs in the original code, which would have affected play on the original PET version too.  One involved the zeroing of the array holding the tile info for the player's hand.  This array is a 0-6 by 0-6 grid.  But the routine meant to put the hand back to an empty state didn't start from zero for the "J" dimension:

1540 FORI=0TO6
1550 FORJ=1TO6:D(I,J)=0:NEXTJ
1560 NEXT

The result was that sometimes, after the first hand, some un-discarded low numbered tiles could be left in the array. Then, when the array was searched for tiles belonging to the player, more than 9 could be found. This error might not have caused an crash in the original program, but in mine it caused the program to try to print a domino to an undefined 10th screen location.  Since those locations were stored in an array (which only went up to 9 locations), an out of array bounds error was triggered.  So I just changed line 1550 above to:

1550 FORJ=0TO6:D(I,J)=0:NEXTJ

This ensures that when the array is repopulated with 9 tiles for a new hand, there is no possibility for old data to be left behind in the first J column.

The other error involved sensing when the computer had played out its final domino. The routine to select the piece would, if possible, select the last tile and designate it as played (=3), and then increment the number of pieces played variable (CD) for the computer. Then it would immediately check if that was the last tile or not (CD<>0).  If it was zero it would proceed to a message that it was "out of dominoes" and then go to the deal a new hand routine.  But this meant the routine would never get to the routine to print the tile on screen and would also miss the end of game/win checks, which follow line 3950.

3950 D(X,Y)=3:D(Y,X)=3:CD=CD-1
3960 IFCD<>0THEN3990
3970 M1$="OUT OF":M2$="DOMINOES"

I noticed that when the computer ran out of tiles it would always flash the "last domino" message and then go directly to a re-deal. Did it win?  Was it a good play?  Did it earn points? The lack of any domino played animation was weird.  So I switched the CD=0 check to the end of the display routine instead.

4140 IFCS<>72THEN4190
4150 M1$="COMPUTER WINS!":M2$="":M$=""
4160 IFPS<66THENM2$="MORE PRACTICE!"
4170 IFPS>65THENM2$="GOOD GAME!"
4180 GOTO2340
4190 D(X,Y)=3:D(Y,X)=3
4191 IFCD=0THEN3970
4195 GOTO1670

Now it displays the domino played (line 3990 - 4130) and then does the win check.  If the computer doesn't win it goes to 4190 and then checks if no tiles are left.  If there are none, it jumps to the no more dominoes message and does a re-deal.  Otherwise, it heads back to the input routine for the next player's move (1670).

I find that it plays a pretty tough game.  But then again, I'm no Dominoes player (no game player of any sort actually), but I forced myself to test it to the point of a "human win."  It was actually kind of fun.

Human for the win!



The game source can be found on my Github:


It can be played online at the Internet Archive:


Another Human for the win!

No comments:

Post a Comment