Personal Computer News


Dominoes

 
Published in Personal Computer News #078

Domino

Pit your wits against your Spectrum in a game of dominoes from Mike Rains in Durham.

The program is a computer implementation of the popular game, written entirely in Basic. One person can play against the computer or two players can play against two computer hands.

Either way, it is possible to watch a demonstration game in which the computer plays all the hands. At the start, each player is dealt seven dominoes and from there the game proceeds according to the normal rules of play. In turn, each player must indicate which domino they wish to play, and where on the board and in which direction. Pressing 'p' in answer to any of these questions indicates a pass.

At the end of the game (detected by the computer), the computer displays all the players' remaining dominoes and the winner's name. The computer's moves are governed entirely by chance but it is surprising how often it wins.

When typing in the program, note that capital letters within quotation marks in lines 70, 80, 800, 900, 1000, 1100, 2530, 3510 and 3520 should all be entered in graphics mode.

The main variables are:

a$(4,7,2) player's dominoes
d$(2,7) user-defined graphics for dominoes
e(2,2) current end dominoes
f(18,31) screen image - records position of dominoes
go current player number
n$(4,10) player's name
o$ demonstration game flag
p1 number of players
t(4) number of dominoes each player has left
v$ string of 32 blanks - used in printing messages
z$(28,2) contains the values of the full domino set

Program Notes

5-20 Dimension arrays, GOSUB introduction and turn off key click
30-60 Read in data
70 Horizontally positioned dominoes
80 Vertically positioned dominoes
145-220 Randomly picks a double as the first domino played by the computer
230 Goes onto next player
240-260 Goes into "computer's turn" routine if demonstration or computer's go
295-318 Puts a flashing A or B at each end of the current game
320-350 Input A or B depending on which end you want to place your domino
355-360 Unable to go
370-420 Which direction - up, down, left, right
430 Current end dominoes
440-470 Input direction using unshifted arrow keys
480-490 Error trap
500-520 Input domino value
530-535 Invalid entry
540-584 Checks that player has that domino
585-597 Goes to relevant subroutine for positioning of domino
599-660 Computer checks player's dominoes to see if any match the ends
665-784 Computer chooses a domino and updates variables
795-820 Places domino to the left
895-910 Places domino to the right
995-1010 Places domino downwards
1095-1110 Length of name
1200-1220 Length of name
1495-1530 Routine for first move
1995-2010 Error message
2495-2570 Displays the player's dominoes
2995-3106 Check for end of game
3108-3109 Game over
3110-3140 Print results
3495-3530 Set up user-defined graphics
4000-4020 Introduction page
4030-4050 How many players?
4046-4060 Do you want a demonstration game?
4061-4090 Input player's names
4095-4540 Set up random set of seven dominoes for each player
4700-4760 Draw playing area
4995-5360 Data

Mike Rains