Multiplication Three-in-a-Row

See all articles from SYNC v1 n4
Author(s): Austin Brown
Publication: SYNC
Pub Details: SYNC v1 n4 (Volume 1, Issue 4)
Date: July/August 1981
Pages: 34-35

“Multiplication Three-in-a Row” is based on the program “Multiplication Bingo,” by Jean Wilson, Special Education teacher at Leadville High School, Leadville, Colorado. She was seeking a way to motivate students who were having difficulty learning to multiply and found that completing five in a row on a Bingo board helped supply the motivation. An array 5 by 5 is too big for the 1K ZX80, but 3 by 3 will fit.

The game proceeds as follows. You select a square on the board. You are then given a multiplication problem to solve. If you solve it within two tries, an “X” goes in the square. If you fail, an “O” goes in the square. If you get three X’s in a row before the board is filled, you win. See Sample Run 1.

The program can be used to build skills in mental arithmetic, pencil and paper arithmetic, or calculator arithmetic. It can generate other ranges of problems by changing lines 120-130. For example, use RND(19) rather than RND(9) to generate factors into the teens.

This is not a tic-tac-toe game. The number or location of 0’s does not matter, as long as you can get three in a row by the time the board is filled.

Programming Notes

The program is built upon the array U(N), N=1,…9, where N represents one of the squares on the board. If the square has not yet been used (the number of the square still shows in the display), U(N)=0. If the player has successfully solved a problem at that square, “X” shows in the display, and U(N)=1. If the player has failed to solve a problem at that square, “0” shows in the display, and U(N)=2.

Use of the array helps the program logic in several ways, as shown in Listing 1. First, we can generate and update the display without the need for nine different string variables and the repetitious logic they require (lines 740-890). Second, we can easily check for an already occupied square,, since U(N) will no longer be zero (line 110). Third, we can also check for three-in-a-row, since we have success if, and only if, all three U’s, and hence their product, are equal to one (lines 230-380). Fourth, we can easily tell when the game is over. As long as there is at least one unoccupied square, its U is zero (lines 300-320). Fifth, we record a right or wrong answer simply by changing the current U (lines 190 and 510).

Tic-Tac-Toe

The program can easily be adapted to a tic-tac-toe game either for two players or for one player against the computer. Success for “O” is tested as well as success for “X” in lines 230-280, except that the product must be eight.

Listing 2 shows the program modified for a two-person game, with the computer simply keeping track of the action. Sample Run 2 shows a game. Modifying the program to play computer against human is left as an exercise for the reader. For example, a simple strategy of random moves by the computer could be implemented by the following changes:

 74 IF J=2 THEN GO TO 500
500 LET N=RND(9)
510 IF NOT U(N)=0 THEN GO TO 500
520 GO TO 120

This strategy can be bewildering to the human encountering it for the first time.

Notes:

REMarks should not be entered into the ZX80. They are included strictly to show the program logic.

Three-in-a-Row

  5 REM Multiplication 3-in-a-row
6 REM A.R.Brown,Jr. 6/1/81
7 REM Initialize
10 RANDOMIZE
20 DIM U(9)
30 FOR I=1 TO 9
40 LET U(I)=0
50 NEXT I
60 GO SUB 700
75 REM Pick square
80 PRINT "WHICH SQUARE?"
90 INPUT N
100 GO SUB 700
110 IF N<1 OR N>9 OR NOT U(N)=0
THEN GO TO 80
115 REM Generate problem
120 LET A=RND(9)
130 LET B=RND(9)
140 PRINT "SQUARE ";N
160 PRINT "WHAT IS ";A;"*";B;"?
"
170 INPUT C
175 REM Check for correct answer
180 IF NOT C=A*B THEN GO TO 500
185 REM Right answer
190 LET U(N)=1
200 GO SUB 700
210 PRINT "RIGHT"
220 PRINT
225 REM Check for 3 in a row
230 FOR K=1 TO 3
240 IF U(K)*U(K+3)*U(K+6)=1 THE
N GO TO 900
250 IF U(3*K-2)*U(3*K-1)*U(3*K)
=1 THEN GO TO 900
260 NEXT K
270 IF U(1)*U(5)*U(9)=1 THEN GO
TO 900
280 IF U(3)*U(5)*U(7)=1 THEN GO
TO 900
295 REM Check for end of game
300 FOR I=1 TO 9
310 IF U(I)=0 THEN GO TO 80
320 NEXT I
355 REM Losing end
360 PRINT "SORRY, YOU LOSE"
370 GO TO 999
495 REM Check error
500 IF F>0 THEN GO TO 600
505 REM 2nd time, answer & move
510 LET U(N)=2
520 GO SUB 700
530 PRINT A;"*";B;"=";A*B
540 GO TO 300
595 REM 1st time, try again
600 LET F=-1
610 PRINT "WRONG,"
620 GO TO 160
695 REM Output tableau
700 CLS
710 LET F=1
720 PRINT "MULTIPLY 3-IN-A-ROW"
730 PRINT
740 PRINT " ";
750 FOR I=1 TO 9
760 LET A$=STR$(I)
770 IF U(I)=1 THEN LET A$="X"
780 IF U(I)=2 THEN LET A$="O"
790 PRINT A$;
800 IF NOT I=3*(I/3) THEN PRINT
" ▒ "; (Shift A; 1 time)
810 IF I=3 OR I=6 THEN GO SUB 8
60
820 NEXT I
830 PRINT
840 PRINT
850 RETURN
860 PRINT
870 PRINT "▒▒▒▒▒▒▒▒▒▒▒"
(Shift A; 11 times)
880 PRINT " ";
890 RETURN
895 REM Winning end
900 PRINT "-- HOORAY, YOU WIN -
-"

[Figure: Listing 1.]

Tic-Tac-Toe

  5 REM Tic-Tac-Toe
6 REM A.R.Brown,Jr. 6/6/81
7 REM Initialize
10 RANDOMIZE
20 DIM U(9)
30 FOR I=1 TO 9
40 LET U(I)=0
50 NEXT I
60 GO SUB 700
65 LET J=0
69 REM Pick square
70 LET J=J-(J/2)*2+1
72 IF J=1 THEN PRINT "X MOVES
"
74 IF J=2 THEN PRINT "O MOVES
"
80 PRINT "WHICH SQUARE?"
90 INPUT N
100 GO SUB 700
110 IF N<1 OR N>9 OR NOT U(N)=0
THEN GO TO 80
120 LET U(N)=J
130 GO SUB 700
225 REM Check for 3 in a row
230 FOR K=1 TO 3
235 LET I=U(K)*U(K+3)*U(K+6)
240 IF I=1 OR I=8 THEN GO TO 90
0
245 LET I=U(3*K-2)*U(3*K-1)*U(3
*K)
250 IF I=1 OR I=8 THEN GO TO 90
0
260 NEXT K
265 LET I=U(1)*U(5)*U(9)
270 IF I=1 OR I=8 THEN GO TO 90
0
275 LET I=U(3)*U(5)*U(7)
280 IF I=1 OR I=8 THEN GO TO 90
0
295 REM Check for end of game
300 FOR I=1 TO 9
310 IF U(I)=0 THEN GO TO 70
320 NEXT I
360 PRINT " - T I E -"
370 GO TO 999
695 REM Output Tableau
700 CLS
710 LET F=1
720 PRINT "TIC-TAC-TOE"
730 PRINT
740 PRINT " ";
750 FOR I=1 TO 9
760 LET A$=STR$(I)
770 IF U(I)=1 THEN LET A$="X"
780 IF U(I)=2 THEN LET A$="O"
790 PRINT A$;
800 IF NOT I=3*(I/3) THEN PRINT
" ▒ "; (Shift A; 1 time)
810 IF I=3 OR I=6 THEN GO SUB 8
60
820 NEXT I
830 PRINT
840 PRINT
850 RETURN
860 PRINT
870 PRINT "▒▒▒▒▒▒▒▒▒▒▒"(Shift A; 11 times)
880 PRINT " ";
890 RETURN
895 REM Winning Ends
900 IF I=1 THEN PRINT "X WINS "
910 IF I=8 THEN PRINT "O WINS "

[Figure: Listing 2.]

Sample Run 1

MULTIPLY 3-IN-A-ROW

 1 ▒ 2 ▒ 3
▒▒▒▒▒▒▒▒▒▒▒
 4 ▒ 5 ▒ 6
▒▒▒▒▒▒▒▒▒▒▒
 7 ▒ 8 ▒ 9

WHICH SQUARE?

SQUARE 1
WHAT IS 9*8?

We gave 72 for the answer

MULTIPLY 3-IN-A-ROW

 X ▒ 2 ▒ 3
▒▒▒▒▒▒▒▒▒▒▒
 4 ▒ 5 ▒ 6
▒▒▒▒▒▒▒▒▒▒▒
 7 ▒ 8 ▒ 9

RIGHT

WHICH SQUARE?

SQUARE 5
WHAT IS 6*9?
WRONG,
WHAT IS 6*9?

We gave first 69, then 54
for the answer
MULTIPLY 3-IN-A-ROW

 X ▒ 2 ▒ 3
▒▒▒▒▒▒▒▒▒▒▒
 4 ▒ X ▒ 6
▒▒▒▒▒▒▒▒▒▒▒
 7 ▒ 8 ▒ 9

RIGHT

WHICH SQUARE?

SQUARE 9
WHAT IS 7*4?
WRONG,
WHAT IS 7*4?

We gave first 21, then 14
for the answer
MULTIPLY 3-IN-A-ROW

 X ▒ 2 ▒ 3
▒▒▒▒▒▒▒▒▒▒▒
 4 ▒ X ▒ 6
▒▒▒▒▒▒▒▒▒▒▒
 7 ▒ 8 ▒ O

Sample Run 2

TIC-TAC-TOE

 1 ▒ 2 ▒ 3
▒▒▒▒▒▒▒▒▒▒▒
 4 ▒ 5 ▒ 6
▒▒▒▒▒▒▒▒▒▒▒
 7 ▒ 8 ▒ 9

X MOVES,
WHICH SQUARE?

X chooses 5.

TIC-TAC-TOE

 1 ▒ 2 ▒ 3
▒▒▒▒▒▒▒▒▒▒▒
 4 ▒ X ▒ 6
▒▒▒▒▒▒▒▒▒▒▒
 7 ▒ 8 ▒ 9

O MOVES,
WHICH SQUARE?

O chooses 8.

TIC-TAC-TOE

 1 ▒ 2 ▒ 3
▒▒▒▒▒▒▒▒▒▒▒
 4 ▒ X ▒ 6
▒▒▒▒▒▒▒▒▒▒▒
 7 ▒ O ▒ 9

X MOVES,
WHICH SQUARE?

X chooses 7.

TIC-TAC-TOE

 1 ▒ 2 ▒ 3
▒▒▒▒▒▒▒▒▒▒▒
 4 ▒ X ▒ 6
▒▒▒▒▒▒▒▒▒▒▒
 X ▒ O ▒ 9

O MOVES,
WHICH SQUARE?

O chooses 3.

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.