100 DEFINT A-Z
110 DIM B(9,9),BR(8,8) 'B IS THE BOARD
120 DIM BSAVE(9,9) 'USED FOR SAVING THE BOARD
130 DIM BRM(8,8) 'MODIFIED BOARD RATINGS
140 M = 3
150 DIM IB(M),JB(M),RB(M) 'FOR M BEST MOVES
160 STRTEND = 50
170 SEARCH = 0
180 REM BR IS THE RATING OF THE BOARD POSITIONS
190 DIM IDIR(8),JDIR(8)
200 DIM XDIR(8),YDIR(8)
210 DIM CHNG(8),TOT(2)
220 REM TWO PLAYERS ARE -1 AND 1
230 REM PLAYER 1 IS BLACK (SMALL SQUARE)
240 REM PLAYER -1 IS WHITE (LARGE SQUARE)
250 REM BLACK (1) GOES FIRST
260 GOSUB 970 'INITIALIZE THE DIRECTIONS
270 REM
280 REM ******************************************
290 REM START NEW GAME
300 GOSUB 3420 'LOAD THE BOARD RATINGS
310 SEARCH = 0
320 GOSUB 4100 'PRINT INTRO MESSAGES AND SET OZ
330 GOSUB 840 'INITIALIZE THE BOARD
340 GOSUB 1110 'PRINT THE BOARD TEMPLATE
350 GOSUB 1400 'PRINT THE INITIAL FOUR PIECES
360 MOVENUM = 4 : PLYR = 1
370 GOSUB 2900 'PRINT PLAYER AND TOTALS
380 EXM = 1 'ASSUME THERE IS A LEGAL MOVE
390 IF(PLYR<>OZ) THEN GOSUB 1490 'MOVE THE CURSOR FOR MOVE
400 IF(PLYR=OZ AND MOVENUM<STRTEND)THEN GOSUB 3760
410 IF(PLYR=OZ AND MOVENUM>=STRTEND)THEN GOSUB 4780
420 IF(EXM=0) THEN GOTO 550
430 GOSUB 2170 'CHECK IF MOVE IS LEGAL AND SET CHANGES
440 IF(LEGAL=0) THEN GOSUB 2460 : GOTO 390
450 REM GOSUB  PRINTS ILLEGAL MOVE MESSAGE
460 GOSUB 2590 'PERFORM THE MOVE (FLIP PIECES)
470 IF(MOVENUM<STRTEND) THEN GOSUB 4520 'MODIFY BRM
480 IF(TOT(0)=0 OR TOT(2)=0) THEN GOTO 610
490 MOVENUM = MOVENUM + 1
500 IF(MOVENUM=64) THEN GOTO 610
510 PLYR = PLYR*(-1)
520 IF(MOVENUM>=STRTEND-1) THEN GOSUB 3190
530 REM CHECK IF PLAYER HAS A LEGAL MOVE
540 IF(EXM=1) THEN GOTO 370
550 REM ONE PLAYER HAS NO LEGAL MOVE
560 GOSUB 3330 'PRINT NO LEGAL MOVE MESSAGE
570 PLYR = PLYR*(-1)
580 GOSUB 3190 'CHECK IF SECOND PLAYER HAS A MOVE
590 IF(EXM=0) THEN GOSUB 3330 : GOTO 610
600 GOTO 370
610 REM END OF GAME
620 REM ******************************************
630 REM
640 PLYR = 0 : GOSUB 2900 'PRINT FINAL TOTALS
650 XPOS = 65 : YPOS = 49 : GOSUB 4040
660 PRINT"END OF THE GAME";
670 YPOS = YPOS + 2 : GOSUB 4040
680 IF(TOT(0)=TOT(2))THEN PRINT"IT WAS A TIE";
690 IF(OZ=-1 AND TOT(0)>TOT(2))THEN PRINT"YOU LOST";
700 IF(OZ=1  AND TOT(0)<TOT(2))THEN PRINT"YOU LOST";
710 IF(OZ=-1 AND TOT(0)<TOT(2))THEN PRINT"YOU WON!";
720 IF(OZ=1  AND TOT(0)>TOT(2))THEN PRINT"YOU WON!";
730 YPOS = YPOS + 1 : GOSUB 4040
740 IF(LEN(INKEY$)<>0) THEN GOTO 740
750 PRINT"HIT Q TO QUIT";
760 YPOS = YPOS + 1 : GOSUB 4040
770 PRINT"OR ANY OTHER KEY";
780 YPOS = YPOS + 1 : GOSUB 4040
790 PRINT"FOR ANOTHER GAME ";
800 A$ = INKEY$ : IF(LEN(A$)=0) THEN GOTO 800
810 IF(A$="Q" OR A$="q") THEN STOP ELSE GOTO 290
820 REM END OF THE PROGRAM
830 REM -------------------------------------------
840 REM INITIALIZE THE BOARD
850 REM MATRIX B(8,8) CONTAINS THE BOARD
860 FOR I = 0 TO 9
870     FOR J = 0 TO 9
880         B(I,J) = 0
890         NEXT J
900     NEXT I
910 B(4,4) = -1 : B(5,5) = -1
920 B(4,5) = 1 : B(5,4) = 1
930 TOT(0) = 2 : TOT(2) = 2
940 RETURN
950 REM END OF INITIALIZING THE BOARD
960 REM -------------------------------------------
970 REM INITIALIZE THE DIRECTIONS
980 REM THE DIRECTIONS ARE AS FOLLOWS:
990 REM 1-8 ARE E,W,S,N,SE,NW,NE,SW, RESPECTIVELY
1000 IDIR(1)=1 : IDIR(2)=-1 : IDIR(3)=0 : IDIR(4)=0
1010 IDIR(5)=1 : IDIR(6)=-1 : IDIR(7)=1 : IDIR(8)=-1
1020 JDIR(1)=0 : JDIR(2)=0 : JDIR(3)=1 : JDIR(4)=-1
1030 JDIR(5)=1 : JDIR(6)=-1 : JDIR(7)=-1 : JDIR(8)=1
1040 XDIR(1)=4 : XDIR(2)=-4 : XDIR(3)=0 : XDIR(4)=0
1050 XDIR(5)=4 : XDIR(6)=-4 : XDIR(7)=4 : XDIR(8)=-4
1060 YDIR(1)=0 : YDIR(2)=0 : YDIR(3)=3 : YDIR(4)=-3
1070 YDIR(5)=3 : YDIR(6)=-3 : YDIR(7)=-3 : YDIR(8)=3
1080 RETURN
1090 REM END OF INITIALIZING THE DIRECTIONS
1100 REM -------------------------------------------
1110 REM PRINT THE BLANK BOARD TEMPLATE
1120 PRINT CHR$(&H1A);
1130 FOR I% = 1 TO 8
1140     FOR J% = 1 TO 2
1150         FOR K% = 1 TO 7
1160             PRINT CHR$(&HC);
1170             PRINT CHR$(&HC);
1180             PRINT CHR$(&HC);
1190             PRINT CHR$(27)+"g";
1200             PRINT CHR$(11);
1210             PRINT CHR$(27)+"G";
1220             NEXT K%
1230          PRINT
1240          NEXT J%
1250     IF(I%=8)THEN GOTO 1360
1260     FOR K% = 1 TO 7
1270         PRINT CHR$(27)+"g";
1271 REM *** NOTE ***  LINES 1280,1290,1300 AND 1320 HAVE BEEN MODIFIED TO
1272 REM  CAUSE THE GRAPHICS OUTPUT TO APPEAR CORRECTLY ON THE OSBORNE 
1273 REM  EXECUTIVE I. THE PROBLEM EXISTS AS OF 18 DEC 83, AND IS DESCRIBED
1274 REM  IN THE FILE `GRAFTEST.BAS', WHICH MAY BE LISTED/RUN FOR DETAILS.
1275 REM     THE MODIFICATION IS AS FOLLOWS; ALL GRAPHICS PAIRS:
1276 REM       CHR$(27)+CHR$(27)
1277 REM     HAVE BEEN CHANGED TO:
1278 REM       CHR$(27)+CHR$(155)
1279 REM  .................... JIM SWITZ, FOG EXECUTIVE LIBRARIAN (18 DEC 83)
1280         PRINT CHR$(27)+CHR$(155);
1290         PRINT CHR$(27)+CHR$(155);
1300         PRINT CHR$(27)+CHR$(155);
1310         PRINT CHR$(12);
1320         IF(K%=7)THEN PRINT CHR$(27)+CHR$(155);:PRINT CHR$(27)+CHR$(155);:PRINT CHR$(27)+CHR$(155);
1330         PRINT CHR$(27)+"G";
1340         NEXT K%
1350      PRINT
1360      NEXT I%
1370 RETURN
1380 REM END OF PRINTING THE BOARD TEMPLATE
1390 REM -------------------------------------------
1400 REM PRINT THE INITIAL FOUR PIECES
1410 PIECE = -1 : X = 45 : Y = 42
1420 GOSUB 1800 'DRAW THE FIRST PIECE
1430 X = 49 : Y = 45 : GOSUB 1800
1440 PIECE = 1 : X = 49 : Y = 42 : GOSUB 1800
1450 X = 45 : Y = 45 : GOSUB 1800
1460 RETURN
1470 REM END OF PRINTING THE INITIAL FOUR PIECES
1480 REM -------------------------------------------
1490 REM MOVE THE CURSOR
1500 X = 33 : Y = 33 : I = 1 : J = 1
1510 PRINT CHR$(27)+"="+CHR$(Y)+CHR$(X);
1520 IF(LEN(INKEY$)<>0) THEN GOTO 1520
1530 A$ = INKEY$ : IF(LEN(A$)=0)THEN GOTO 1530
1540 IF(A$=CHR$(13)) THEN GOTO 1770
1550 IF(A$="L") THEN GOSUB 5570 'LEGAL MOVE?
1560 IF(A$="L" AND EXM=0) THEN GOTO 1770
1570 IF(A$="L" AND EXM=1) THEN GOTO 1530
1580 XDEL = 0 : YDEL = 0
1590 IF(A$="4") THEN XDEL = -4
1600 IF(A$="6") THEN XDEL = 4
1610 IF(A$="8") THEN YDEL = -3
1620 IF(A$="2") THEN YDEL = 3
1630 IF(A$="3") THEN XDEL = 4 : YDEL = 3
1640 IF(A$="9") THEN XDEL = 4 : YDEL = -3
1650 IF(A$="7") THEN XDEL =-4 : YDEL = -3
1660 IF(A$="1") THEN XDEL =-4 : YDEL = 3
1670 IF(XDEL=0 AND YDEL=0) THEN GOTO 1530
1680 XNEW = X + XDEL : YNEW = Y + YDEL
1690 REM DON'T MOVE CURSOR OFF THE BOARD
1700 IF(XNEW<32 OR XNEW >62) THEN GOTO 1530
1710 IF(YNEW<32 OR YNEW >54) THEN GOTO 1530
1720 X = XNEW : Y = YNEW
1730 I = I + SGN(XDEL) : J = J + SGN(YDEL)
1740 PRINT
1750 PRINT CHR$(27)+"="+CHR$(Y)+CHR$(X);
1760 GOTO 1530
1770 RETURN
1780 REM END OF MOVING THE CURSOR
1790 REM -----------------------------------------
1800 REM DRAW A PIECE
1810 REM (X,Y) IS THE POSITION; PIECE = 1, -1
1820 XOLD = X : YOLD = Y
1830 X = X - 1 : Y = Y - 1
1840 PRINT CHR$(&H1E);
1850 PRINT CHR$(27)+"="+CHR$(Y)+CHR$(X);
1860 IF(PIECE=-1)THEN GOTO 2020
1870 REM PIECE = 1
1880 PRINT" ";
1890 PRINT CHR$(27)+"g";
1900 PRINT CHR$(24);
1910 PRINT CHR$(27)+"G";
1920 PRINT" ";
1930 Y = Y + 1
1940 PRINT
1950 PRINT CHR$(27)+"="+CHR$(Y)+CHR$(X);
1960 PRINT" ";
1970 PRINT CHR$(27)+"g";
1980 PRINT CHR$(23);
1990 PRINT CHR$(27)+"G";
2000 PRINT" ";
2010 GOTO 2120
2020 REM PIECE = -1
2030 PRINT CHR$(27)+"g";
2040 PRINT CHR$(22); : PRINT CHR$(23);
2050 PRINT CHR$(22); : PRINT CHR$(27)+"G";
2060 Y = Y + 1
2070 PRINT
2080 PRINT CHR$(27)+"="+CHR$(Y)+CHR$(X);
2090 PRINT CHR$(27)+"g";
2100 PRINT CHR$(22); : PRINT CHR$(24);
2110 PRINT CHR$(22); : PRINT CHR$(27)+"G";
2120 REM
2130 X = XOLD : Y = YOLD
2140 RETURN
2150 REM END OF DRAWING THE PIECE
2160 REM ------------------------------------------
2170 REM CHECK IF MOVE I,J IS LEGAL
2180 REM LEGAL = 0 IF ILLEGAL, 1 IF LEGAL
2190 REM CHNG CONTAINS THE # OF CHANGES IN DIR I
2200 REM SCHNG IS THE TOTAL NUMBER OF CHANGES
2210 REM SCHNG DOES NOT COUNT THE MOVE ITSELF
2220 SCHNG = 0
2230 LEGAL = 0
2240 IF(I=0 OR I=9) THEN STOP
2250 IF(J=0 OR J=9) THEN STOP
2260 IF(B(I,J)<>0) THEN GOTO 2430
2270 REM CHECK THE EIGHT DIRECTIONS
2280 FOR IND = 1 TO 8 'IND IS THE CURRENT DIRECTION
2290     CHNG(IND) = 0
2300     IDEL = IDIR(IND) : JDEL = JDIR(IND)
2310     INEW = I + IDEL  : JNEW = J + JDEL
2320     IF(PLYR<> -1* B(INEW,JNEW))THEN GOTO 2390
2330     FOR JND1 = 1 TO 8
2340         INEW = INEW + IDEL : JNEW = JNEW + JDEL
2350         CHNG(IND) = CHNG(IND) + 1
2360         IF(B(INEW,JNEW)=0)THEN CHNG(IND)=0:GOTO 2390
2370         IF(B(INEW,JNEW)=PLYR)THEN GOTO 2390
2380         NEXT JND1
2390 REM DONE CURRENT DIRECTION
2400     SCHNG = SCHNG + CHNG(IND)
2410     NEXT IND
2420 IF(SCHNG > 0) THEN LEGAL = 1
2430 RETURN
2440 REM END OF LEGAL MOVE SUBROUTINE
2450 REM -----------------------------------------
2460 REM PRINT NOT LEGAL MOVE MESSAGE
2470 XPOS = 64 : YPOS = 50 : GOSUB 4040
2480 PRINT"SORRY, THAT IS NOT";
2490 YPOS = YPOS + 1 : GOSUB 4040
2500 PRINT"   A LEGAL MOVE";
2510 FOR TIME = 1 TO 400 : DUM = 4.3*8.7 : NEXT TIME
2520 YPOS = YPOS - 1 : GOSUB 4040
2530 PRINT"                   ";
2540 YPOS = YPOS + 1 : GOSUB 4040
2550 PRINT"               ";
2560 RETURN
2570 REM END OF PRINTING NOT LEGAL MESSAGE 
2580 REM ------------------------------------------
2590 REM PERFORM THE MOVE (FLIP PIECES)
2600 PIECE = PLYR
2610 B(I,J) = PLYR
2620 JSUB = PLYR + 1
2630 IF(SEARCH=0) THEN TOT(JSUB) = TOT(JSUB) + 1
2640 IF(JSUB=2) THEN KSUB=0 ELSE KSUB=2
2650 IF(SEARCH=0) THEN GOSUB 1800 'DRAW THE PIECE
2660 IF(SEARCH=1) THEN GOTO 2690
2670 FOR TIME = 1 TO 100 : DUM=2.3*8.9 : NEXT TIME
2680 IF(SEARCH=0) THEN GOSUB 1800 'DRAW THE PIECE AGAIN
2690 REM NOW FLIP THE REMAINING PIECES
2700 FOR IND = 1 TO 8
2710     IF(CHNG(IND)=0) THEN GOTO 2860
2720     IDEL = IDIR(IND) : JDEL = JDIR(IND)
2730     XDEL = XDIR(IND) : YDEL = YDIR(IND)
2740     ISAVE = I : JSAVE = J
2750     XSAVE = X : YSAVE = Y
2760     FOR JND = 1 TO CHNG(IND)
2770         I = I + IDEL : J = J + JDEL
2780         X = X + XDEL : Y = Y + YDEL
2790         IF(SEARCH=0)THEN GOSUB 1800 'DRAW THE PIECE
2800         B(I,J) = PLYR
2810         IF(SEARCH=0)THEN TOT(JSUB) = TOT(JSUB) + 1
2820         IF(SEARCH=0)THEN TOT(KSUB) = TOT(KSUB) - 1
2830         NEXT JND
2840     X = XSAVE : Y = YSAVE
2850     I = ISAVE : J = JSAVE
2860     NEXT IND
2870 RETURN
2880 REM END OF PERFORM THE MOVE
2890 REM ------------------------------------------
2900 REM PRINT PLAYER'S TOTAL AND WHOSE TURN IT IS
2910 XPOS = 74 : YPOS = 35 : GOSUB 4040
2920 PRINT"TOTAL"
2930 YPOS = YPOS + 1 : GOSUB 4040
2940 PRINT"PIECES"
2950 PIECE = 1
2960 XPOS = 65 : YPOS = 38 : GOSUB 4040
2970 PRINT" PLAYER   "; TOT(2);
2980 YPOS = YPOS + 1 : GOSUB 4040
2990 PRINT"                         ";
3000 X = 68 : Y = 41
3010 GOSUB 1800
3020 IF(PLYR=1 AND PLYR<>OZ) THEN PRINT"<- YOUR MOVE";
3030 IF(PLYR=1 AND PLYR=OZ)  THEN PRINT"<- MY MOVE";
3040 IF(PLYR<>1) THEN             PRINT"            ";
3050 XPOS = 65 : YPOS = 44 : GOSUB 4040
3060 PRINT" PLAYER   "; TOT(0);
3070 YPOS = YPOS + 1 : GOSUB 4040
3080 PRINT"                          ";
3090 X = 68 : Y = 47
3100 PIECE = -1
3110 GOSUB 1800
3120 IF(PLYR=-1 AND PLYR<>OZ) THEN PRINT"<- YOUR MOVE";
3130 IF(PLYR=-1 AND PLYR=OZ)  THEN PRINT"<- MY MOVE";
3140 IF(PLYR<>-1)             THEN PRINT"            ";
3150 PRINT
3160 RETURN
3170 REM END OF PRINTING PLAYER'S TOTALS
3180 REM -----------------------------------------
3190 REM CHECK IF PLAYER HAS ANY LEGAL MOVE
3200 REM EXM = 1 IF THERE EXISTS A LEGAL MOVE
3210 REM EXM = 0 IF PLAYER HAS NO LEGAL MOVES
3220 EXM = 0
3230 FOR I = 1 TO 8
3240     FOR J = 1 TO 8
3250         GOSUB 2170
3260         IF(LEGAL=1) THEN GOTO 3290
3270         NEXT J
3280     NEXT I
3290 IF(LEGAL=1) THEN EXM = 1
3300 RETURN
3310 REM END OF CHECKING IF PLAYER HAS LEGAL MOVE
3320 REM -----------------------------------------
3330 REM PRINT NO LEGAL MOVE MESSAGE
3340 IF(PLYR=1) THEN XPOS=66 : YPOS = 39
3350 IF(PLYR=-1)THEN XPOS=66 : YPOS = 45
3360 GOSUB 4040
3370 PRINT"NO LEGAL MOVE";
3380 FOR TIME = 1 TO 450 : DUM=2.3*3.4 : NEXT TIME
3390 RETURN
3400 REM END OF NO LEGAL MOVE MESSAGE
3410 REM -----------------------------------------
3420 REM LOAD THE BOARD RATINGS
3430 FOR I = 1 TO 8
3440     FOR J = 1 TO 8
3450         BR(I,J) = 0
3460         GOSUB 3660  'COMPUTE NRM=NORM(I,J)
3470         IF(NRM=2) THEN BR(I,J) = -2 
3480         IF(NRM=3) THEN BR(I,J) = 3 
3490         NEXT J
3500     NEXT I
3510 BR(1,2)=2 : BR(2,1)=2 : BR(1,7)=2 : BR(7,1)=2
3520 BR(2,8)=2 : BR(8,2)=2 : BR(7,8)=2 : BR(8,7)=2
3530 BR(2,2) = -4 : BR(2,7) = -4
3540 BR(7,2) = -4 : BR(7,7) = -4
3550 BR(1,1) = 6  : BR(1,8) = 6
3560 BR(8,1) = 6  : BR(8,8) = 6
3570 BR(3,3)=1 : BR(3,6)=1 : BR(6,3)=1 : BR(6,6)=1
3580 FOR I = 1 TO 8
3590     FOR J = 1 TO 8
3600         BRM(I,J) = BR(I,J)
3610         NEXT J
3620     NEXT I
3630 RETURN
3640 REM END OF LOAD BR SUBROUTINE
3650 REM -----------------------------------------
3660 REM COMPUTE NORM(I,J), THE DISTANCE FROM CENTER
3670 REM STORE THE NORM IN NRM
3680 IF(I>4) THEN INRM = I - 5
3690 IF(I<=4) THEN INRM = 4 - I
3700 IF(J>4) THEN JNRM = J - 5
3710 IF(J<=4) THEN JNRM = 4 - J
3720 IF(INRM>JNRM)THEN NRM=INRM ELSE NRM=JNRM
3730 RETURN
3740 REM END OF COMPUTE NORM(I,J) ROUTINE
3750 REM -----------------------------------------
3760 REM DETERMINE OZ'S MOVE
3770 IBEST = 0 : JBEST = 0
3780 RBEST! = -30000
3790 IF(SEARCH=0) THEN XPOS = 66 : YPOS = 50 : GOSUB 4040
3800 IF(SEARCH=0) THEN PRINT"I'M THINKING";
3810 IF(SEARCH=0) THEN YPOS = YPOS + 1 : GOSUB 4040
3820 FOR I = 1 TO 8
3830     IF(SEARCH=0) THEN PRINT"X";
3840     FOR J = 1 TO 8
3850         GOSUB 2170 'CHECK IF MOVE IS LEGAL
3860         IF(LEGAL=0) THEN GOTO 3900
3870         IF(MOVENUM>STRTEND) THEN FAC!=0 ELSE FAC!=1
3880         RATING! = SCHNG + BRM(I,J)*FAC!
3890         IF(RATING!>RBEST!)THEN IBEST=I:JBEST=J:RBEST!=RATING!
3900         NEXT J
3910      NEXT I
3920 I = IBEST : J = JBEST
3930 IF(SEARCH=1) THEN GOTO 4010
3940 REM ERASE I'M THINKING MESSAGE
3950 X = 29 + 4*I : Y = 30 + 3*J
3960 YPOS = YPOS - 1 : GOSUB 4040
3970 PRINT"               ";
3980 YPOS = YPOS + 1 : GOSUB 4040
3990 PRINT"            ";
4000 IF(IBEST=0 OR JBEST=0) THEN EXM=0
4010 RETURN
4020 REM END OF DETERMINE OZ'S MOVE
4030 REM -----------------------------------------
4040 REM REPOSITION CURSOR AT (XPOS,YPOS)
4050 PRINT
4060 PRINT CHR$(27)+"="+CHR$(YPOS)+CHR$(XPOS);
4070 RETURN
4080 REM END OF REPOSITIONING THE CURSOR
4090 REM -----------------------------------------
4100 REM PRINT INTRO MESSAGES AND SET OZ
4110 REM OZ <> 0 IF OZZIE PLAYS
4120 REM OZ = 0  IF OZZIE DOES NOT PLAY
4130 PRINT CHR$(&H1A);
4140 XPOS = 42 : YPOS = 33 : GOSUB 4040
4150 PRINT"OSBORNE OTHELLO"
4160 PRINT"          by Mark Broadie";
4170 XPOS = 32 : YPOS = 36: GOSUB 4040
4180 PRINT"    CURSOR MOVEMENT IS CONTROLLED"
4190 PRINT"         BY THE NUMBER KEYS:"
4200 PRINT
4210 PRINT"               8"
4220 PRINT"            7  ^  9"
4230 PRINT"              \|/   "
4240 PRINT"          4<--- --->6"
4250 PRINT"              /|\  "
4260 PRINT"            1  |  3 "
4270 PRINT"               2"
4280 PRINT
4290 PRINT"    MOVE THE CURSOR WITH NUMBER KEYS"
4300 PRINT"    AND THEN HIT RETURN TO ENTER MOVE."
4310 PRINT"    IF YOU THINK THAT YOU DO NOT HAVE"
4320 PRINT"    A LEGAL MOVE HIT 'L'. "
4330 PRINT"    NOTE: ALPHA LOCK SHOULD BE ON."
4340 PRINT
4350 IF(LEN(INKEY$)<>0) THEN GOTO 4350
4360 PRINT"    DO YOU WANT OZZIE TO PLAY (Y OR N)? ";
4370 A$ = INKEY$ : IF(LEN(A$)=0) THEN GOTO 4370
4380 IF(A$<>"Y" AND A$<>"N") THEN GOTO 4370
4390 PRINT A$
4400 IF(A$="N") THEN OZ = 0 : GOTO 4490
4410 REM A$ = "Y"
4420 PRINT
4430 IF(LEN(INKEY$)<>0) THEN GOTO 4430
4440 PRINT"    DO YOU WANT TO GO FIRST (Y OR N)? ";
4450 A$ = INKEY$ : IF(LEN(A$)=0) THEN GOTO 4450
4460 IF(A$<>"Y" AND A$<>"N") THEN GOTO 4450
4470 PRINT A$
4480 IF(A$="N") THEN OZ = 1 ELSE OZ = -1
4490 RETURN
4500 END OF PRINT INSTRUCTIONS
4510 REM -----------------------------------------
4520 REM MODIFY BRM
4530 IF(PLYR=OZ OR OZ=0) THEN GOTO 4740
4540 GOSUB 3660 'COMPUTE NRM = NORM(I,J)
4550 IF(NRM<2) THEN GOTO 4740
4560 REM NRM = 3
4570 IF(I=1 AND J=1) THEN BRM(2,2)=0 : GOTO 4740
4580 IF(I=1 AND J=8) THEN BRM(2,7)=0 : GOTO 4740
4590 IF(I=8 AND J=1) THEN BRM(7,2)=0 : GOTO 4740
4600 IF(I=8 AND J=8) THEN BRM(7,7)=0 : GOTO 4740
4610 IF(J=1 OR J=8) THEN GOTO 4680
4620 IF(B(I,J+1)<>0 OR B(I,J+2)<>0)THEN GOTO 4740
4630 IF(B(I,J-1)<>0 OR B(I,J-2)<>0)THEN GOTO 4740
4640 BRM(I,J+1)=-3 : BRM(I,J-1)=-3 
4650 IF(J=2) THEN BRM(I,1)=6
4660 IF(J=7) THEN BRM(I,8)=6
4670 GOTO 4740
4680 REM 
4690 IF(B(I+1,J)<>0 OR B(I+2,J)<>0)THEN GOTO 4740
4700 IF(B(I-1,J)<>0 OR B(I-2,J)<>0)THEN GOTO 4740
4710 BRM(I+1,J)=-3 : BRM(I-1,J)=-3 
4720 IF(I=2) THEN BRM(1,J)=6
4730 IF(I=7) THEN BRM(8,J)=6
4740 REM  RETURN POINT
4750 RETURN
4760 REM END OF MODIFYING BRM
4770 REM -----------------------------------------
4780 REM DETERMINE OZ'S MOVE IN THE ENDGAME
4790 REM DETERMINE BEST M MOVES
4800 SEARCH = 1
4810 XPOS = 66 : YPOS = 50 : GOSUB 4040
4820 PRINT"I'M THINKING";
4830 YPOS = YPOS + 1 : GOSUB 4040 
4840 FOR IND = 1 TO M
4850     IB(IND)=0 : JB(IND)=0 : RB(IND)=-30000
4860     NEXT IND
4870 FOR I = 1 TO 8
4880      IF(I=4)THEN PRINT"X";
4890      IF(I=8)THEN PRINT"X";
4900     FOR J = 1 TO 8
4910         GOSUB 2170 'IS MOVE LEGAL
4920         IF(LEGAL=0) THEN GOTO 5050
4930         FOR K = 1 TO M
4940             IF(SCHNG < RB(K)) THEN GOTO 5040
4950             IT=IB(K):JT=JB(K):RT=RB(K)
4960             IB(K)=I:JB(K)=J:RB(K)=SCHNG
4970             IF(K=M) THEN GOTO 5050
4980             FOR L = K+1 TO M
4990                 TMP=IB(L):IB(L)=IT:IT=TMP
5000                 TMP=JB(L):JB(L)=JT:JT=TMP
5010                 TMP=RB(L):RB(L)=RT:RT=TMP
5020                 NEXT L
5030             K = M
5040             NEXT K
5050          NEXT J
5060      NEXT I
5070 REM COPY B INTO BSAVE, PLYR INTO PSAVE
5080 GOSUB 5390 : PSAVE = PLYR
5090 FOR IIND = 1 TO M
5100     IF(IB(IIND)=0) THEN GOTO 5210
5110     I = IB(IIND) : J = JB(IIND)
5120     GOSUB 2170 'LEGAL MOVE AND SET CHNG
5130     GOSUB 2590 'PERFORM MOVE ON B
5140     PLYR = PLYR*(-1)
5150     PRINT"XX";
5160     GOSUB 3760 'DETERMINE BEST RESPONSE
5170     IF(I=0)THEN RB(IIND)=RB(IIND)+5000:ELSE RB(IIND)=RB(IIND)-RBEST! 
5180     'THERE MAY BE NO LEGAL RESPONSE
5190     PLYR = PLYR*(-1)
5200     GOSUB 5480 'COPY BSAVE INTO B
5210     NEXT IIND
5220 REM DETERMINE BEST MOVE OF THE THREE
5230 TMP=-30000
5240 FOR IIND = 1 TO M
5250     IF(RB(IIND)>TMP)THEN INDB=IIND:TMP=RB(IIND)
5260     NEXT IIND
5270 SEARCH = 0
5280 PLYR = PSAVE : GOSUB 5480
5290 I = IB(INDB) : J = JB(INDB)
5300 X = 29 + 4*I : Y = 30 + 3*J
5310 REM ERASE I'M THINKING MESSAGE
5320 XPOS = 66 : YPOS = 50 : GOSUB 4040
5330 PRINT"             ";
5340 YPOS = YPOS + 1 : GOSUB 4040
5350 PRINT"             ";
5360 RETURN
5370 REM END OF DETERMINE OZ'S MOVE IN ENDGAME 
5380 REM -----------------------------------------
5390 REM COPY B INTO BSAVE
5400 FOR ROW = 0 TO 9
5410     FOR COL = 0 TO 9
5420         BSAVE(ROW,COL) = B(ROW,COL)
5430         NEXT COL
5440     NEXT ROW
5450 RETURN
5460 REM END OF COPY B INTO BSAVE
5470 REM -----------------------------------------
5480 REM COPY BSAVE INTO B
5490 FOR ROW = 0 TO 9
5500     FOR COL = 0 TO 9
5510         B(ROW,COL) = BSAVE(ROW,COL)
5520         NEXT COL
5530     NEXT ROW
5540 RETURN
5550 REM END OF COPY BSAVE INTO B
5560 REM -----------------------------------------
5570 REM CHECK IF PLAYER HAS LEGAL MOVE
5580 REM CALLED FROM MOVE CURSOR ROUTINE
5590 REM FIRST PRINT MESSAGE 
5600 XPOS = 65 : YPOS = 50 : GOSUB 4040
5610 PRINT"CHECKING FOR A";
5620 YPOS = YPOS + 1 : GOSUB 4040
5630 PRINT"LEGAL MOVE ...";
5640 GOSUB 3190
5650 REM ERASE MESSAGE
5660 YPOS = 50 : GOSUB 4040
5670 PRINT"               ";
5680 YPOS = 51 : GOSUB 4040
5690 PRINT"               ";
5700 REM IF NO MOVE (EXM=0) THEN RETURN
5710 IF(EXM=0) THEN GOTO 5900
5720 REM IF THERE IS A MOVE (EXM=1) SET CURSOR
5730 REM AND PRINT MESSAGE
5740 YPOS = 50 : GOSUB 4040
5750 PRINT"THERE IS AT LEAST";
5760 YPOS = 51 : GOSUB 4040
5770 PRINT"ONE LEGAL MOVE -";
5780 YPOS = 52 : GOSUB 4040
5790 PRINT"SEE CURSOR";
5800 X = 29 + 4*I : Y = 30 + 3*J : PRINT
5810 PRINT CHR$(27)+"="+CHR$(Y)+CHR$(X);
5820 FOR TIME = 1 TO 550 : DUM=4.3*2.2 : NEXT TIME
5830 YPOS = 50 : GOSUB 4040
5840 PRINT"                       ";
5850 YPOS = 51 : GOSUB 4040
5860 PRINT"                     ";
5870 YPOS = 52 : GOSUB 4040
5880 PRINT"                        "; : PRINT
5890 PRINT CHR$(27)+"="+CHR$(Y)+CHR$(X);
5900 RETURN
5910 REM END OF CHECK FOR LEGAL MOVE
5920 REM -----------------------------------------
)+"="+CHR$(Y)+CHR$(X);
5900 RETURN
5910 REM END OF CHECK FOR LEGAL MOVE
59