10 ' https://archive.org/details/byte-magazine-1977-10/page/n61/mode/2up
20 '
30 '
40 '
50 '
60 '
70 '
80 ' OTHELLO AUTHOR: RICHARD O. DUDA PLAYS THE GAME "OTHELLO" WITH TWO STRATEGIES:
' 1. TAKE THE MAXIMUM NUMBER OF PIECES
' 2. ADD A BONUS FOR OUTSIDE POSITION BOARD IS THE ARRAY A, BOUNDED BY 0'S (BLANKS) A = 0 FOR EMPTY SQUARE A = B FOR BLACK SQUARE -- X (INTERNALLY -1) A = W FOR WHITE SQUARE -- 0 (INTERNALLY +1)
90 ' I AND J ALWAYS USED FOR ROW/COLUMN INDICES
100 ' I4 AND J4 STORE INC'ENTS TO THE 8 NEIGHBORS
110 ' C$ AND D$ STORE CHARACTERS A-H,X,.,O FOR OUTPUT
120 DIM A
(9, 9), I4
(8), J4
(8), C$
(8), D$
(2) 130 ' INITIAL GREETING
140 PRINT "GREETINGS FROM OTHELLO" 150 PRINT "DO YOU WANT INSTRUCTIONS (Y OR N) ";
200 PRINT "OTHELLO IS PLAYED ON AN 8 X 8 CHECKER BOARD," 210 PRINT "ROWS NUMBERED 1 TO 8 AND COLUMNS A TO H." 220 PRINT "THE INITIAL CONFIGURATION IS ALL BLANK, EXCEPT" 230 PRINT "FOR THE CENTER FOUR SQUARES, WHICH FORM THE" 280 PRINT "TRY TO PLACE YOUR PIECE SO THAT IT 'OUTFLANKS'" 290 PRINT "MINE, CREATING A HORIZONTAL, VERTICAL, OR" 300 PRINT "DIAGONAL RUN OF MY PIECES BOUNDED AT EACH END" 310 PRINT "BY AT LEAST ONE OF YOURS. THIS WILL 'FLIP' MY" 320 PRINT "PIECES, TURNING THEM INTO YOURS." 330 PRINT "NOTE: YOU MUST CAPTURE AT LEAST ONE OF MY" 340 PRINT "PIECES IN THIS WAY IF IT IS AT ALL POSSIBLE." 350 PRINT "IF IT IS NOT POSSIBLE, YOU FORFEIT YOUR TURN BY" 360 PRINT "ENTERING 0,0 FOR YOUR (ROW,COL) MOVE." 380 ' INITIALIZE
390 PRINT "SHOULD I WAIT BEFORE MAKING MY MOVES (Y OR N) ";
400 F2 = 0
440 F2 = 1
450 PRINT "OK. TYPING ANY CHARACTER WILL LET ME GO." 460 PRINT "SHOULD I PLAY MY BEST STRATEGY (Y OR N)" 470 S2 = 0
510 S2 = 2
520 B = -1
530 W = 1
540 D$(B + 1) = "X"
550 D$(0 + 1) = "."
560 D$(W + 1) = "0"
600 DATA 0,-1,-1,-1,0,1,1,1 640 DATA 1,1,0,-1,-1,-1,0,1 680 DATA "A","B","C","D","E","F","G","H" 690 ' SET UP A NEW GAME
720 A(I, J) = 0
750 A(4, 4) = W
760 A(5, 5) = W
770 A(4, 5) = B
780 A(5, 4) = B
790 C1 = 2
800 H1 = 2
810 N1 = 4
820 Z = 0
830 ' HUMAN'S CHOICES
840 PRINT "DO YOU WANT TO HAVE X OR 0 ";
850 C = W
860 H = B
900 C = B
910 H = W
920 PRINT "DO YOU WANT TO GO FIRST (Y OR N) ";
960 ' PRINT INITIAL BOARD
990 ' COMPUTER'S MOVE
1020 B1 = -1
1030 I3 = J3 = 0
1040 T1 = C
1050 T2 = H
1060 ' SCAN FOR BLANK SQUARE
1090 IF A
(I
, J
) <> 0 THEN 1380 1100 ' FOUND A BLANK SQUARE
1110 ' DOES IT HAVE AN OPPONENT AS A NEIGHBOR?
1140 ' FOUND AN OPPONENT AS A NEIGHBOR
1150 ' HOW MANY OF HIS PIECES CAN WE FLIP?
1160 ' (DON'T DO IT NOW)
1170 U = -1
1190 ' EXTRA POINTS FOR BOUNDARY POSITION
1210 IF (I
- 1) * (I
- 8) <> 0 THEN 1230 1220 S1 = S1 + S2
1230 IF (J
- 1) * (J
- 8) <> 0 THEN 1260 1240 S1 = S1 + S2
1250 ' IS THIS BETTER THAN THE BEST FOUND SO FAR?
1280 ' A TIE; RANDOM DECISION
1290 ' THE NEXT TWO EXECUTABLE STATEMENTS CAN BE DELETED
1300 ' FOR A VERSION OF BASIO WITHOUT RANDOM NUMBERS
1330 ' YES
1340 B1 = S1
1350 I3 = I
1360 J3 = J
1370 ' END OF SCAN LOOP
1400 ' COULD WE DO ANYTHING?
1420 ' NO
1430 PRINT "I HAVE TO FORFEIT MY MOVE" 1450 Z = 1
1470 ' MAKE THE MOVE
1480 Z = 0
1490 PRINT "I WILL MOVE TO ";
1530 I = I3
1540 J = J3
1550 U = 1
1570 C1 = C1 + S1 + 1
1580 H1 = H1 - S1
1590 N1 = N1 + 1
1600 PRINT "THAT GIVES ME ";
1620 PRINT " OF YOUR PIECES" 1630 ' PRINT OUT BOARD
1650 ' TEST FOR END OF GAME
1680 ' HUMAN'S MOVE
1690 T1 = H
1700 T2 = C
1710 PRINT "YOUR MOVE -- (ROW, COL) ";
1760 PRINT "ARE YOU FORFEITING YOUR TURN (Y OR N)" 1800 Z = 1
1860 ' CHECK IF BLANK
1880 PRINT "SORRY, THAT SQUARE IS OCCUPIED; TRY AGAIN." 1900 ' CHECK FOR LEGAL NEIGHBOR
1930 PRINT "SORRY, YOU ARE NOT NEXT TO ONE OF MY PIECES;" 1960 ' CHECK IF LEGAL RUN
1970 U = -1
2000 PRINT "SORRY, THAT DOESN'T FLANK A ROW; TRY AGAIN" 2020 ' EVERYTHING LEGAL; MAKE HUMAN'S MOVE
2030 Z = 0
2040 PRINT "THAT GIVES YOU ";
2060 PRINT " OF MY PIECES" 2070 U = 1
2090 H1 = H1 + S1 + 1
2100 C1 = C1 - S1
2110 N1 = N1 + 1
2120 '. PRINT OUT BOARD
2140 ' TEST FOR END OF GAME
2180 ' END OF GAME WRAPUP
2220 PRINT " PIECES AND I HAVE ";
2240 PRINT " PIECES -- ";
2270 PRINT "SORRY, I WON THAT ONE." 2320 C1 = C1 - H1
2340 C1 = -C1
2350 C1 = (64 * C1) / N1
2360 PRINT "THAT WAS A ";
2410 PRINT "PERFECT GAME." 2510 PRINT "DO YOU WANT TO PLAY ANOTHER GAME (Y OR N) ";
2550 PRINT "THANKS FOR PLAYING." 2570 '
2580 ' SUBROUTINE TEST-FOR-PROPER-NEIGHBOR
2590 ' ASSUMES:
2600 ' I,J LOCATES A BLANK SQUARE
2610 ' YOU HOPE TO SEE AN ADJACENT T2 (. -T1)
2640 IF A
(I
+ I1
, J
+ J1
) = T2
THEN 2710 2670 ' NO T2 FOUND; FAILURE
2680 F1 = 0
2700 ' SUCCESS
2710 F1 = 1
2730 ' SUBROUTINE SCORE-AND-UPDATE
2740 ' ASSUMES:
2750 ' (I,J) IS A TENTATIVE PLACE FOR A PIECE T1.
2760 ' WANT RUNS OF T2 . -T1, TERMINATED BY A T1.
2770 ' IF U IS TRUE (1), MARK THOSE RUNS AS T1'S.
2780 ' RETURN SUM OF ALL RUNS (T2'S ONLY) IN S1.
2790 ' MAIN PROGRAM CONTAINS THE FOLLOWING ARRAYS:
2800 ' i4: 0 -1 -1 -1 0 1 1 1
2810 ' J4: 1 1 0 -1 -1 -1 0 1
2820 S1 = 0
2840 I5 = I4(K)
2850 J5 = J4(K)
2860 I6 = I + I5
2870 J6 = J + J5
2880 S3 = 0
2890 IF A
(I6
, J6
) <> T2
THEN 3070 2900 ' LOOP THROUGH THE RUN
2910 S3 = S3 + 1
2920 I6 = I6 + I5
2930 J6 = J6 + J5
2940 IF A
(I6
, J6
) = T1
THEN 2970 2950 IF A
(I6
, J6
) = 0 THEN 3070 2970 S1 = S1 + S3
2990 ' UPDATE BOARD
3000 I6 = I
3010 J6 = J
3030 A(I6, J6) = T1
3040 I6 = I6 + I5
3050 J6 = J6 + J5
3090 ' SUBROUTINE PRINT-BOARD
3110 PRINT " A B C D E F G H" 3160 PRINT D$
(A
(I
, J
) + 1);