1 PRINT CHR$(26);TAB(32);"HEXAPAWN":PRINT:WIDTH 80
2 PRINT TAB(15);"CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY"
3 PRINT:PRINT:PRINT
4 REM  HEXAPAWN:  INTERPRETATION OF HEXAPAWN GAME AS PRESENTED IN
5 REM  MARTIN GARDNER'S "THE UNEXPECTED HANGING AND OTHER MATHEMATIC-
6 REM  AL DIVERSIONS", CHAPTER EIGHT:  A MATCHBOX GAME-LEARNING MACHINE
7 REM  ORIGINAL VERSION FOR H-P TIMESHARE SYSTEM BY R.A. KAAPKE 5/5/76
8 REM  INSTRUCTIONS BY JEFF DALTON
9 REM  CONVERSION TO MITS BASIC BY STEVE NORTH
10 DIM B(19,9),M(19,4),S(9),P$(3)
15 W=0: L=0
20 DEF FNR(X)=-3*(X=1)-(X=3)-4*(X=6)-6*(X=4)-7*(X=9)-9*(X=7)+FNS(X)
25 DEF FNS(X)=-X*(X=2 OR X=5 OR X=8)
30 DEF FNM(Y)=Y-INT(Y/10)*10
35 P$="X.O"
40 FOR I=1 TO 19: FOR J=1 TO 9: READ B(I,J): NEXT J: NEXT I
45 FOR I=1 TO 19: FOR J=1 TO 4: READ M(I,J): NEXT J: NEXT I
50 PRINT "INSTRUCTIONS (Y-N)";
60 INPUT A$
70 A$=LEFT$(A$,1)
80 IF A$="Y" THEN 2000
90 IF A$<>"N" THEN 50
100 X=0: Y=0
111 S(4)=0: S(5)=0: S(6)=0
112 S(1)=-1: S(2)=-1: S(3)=-1
113 S(7)=1: S(8)=1: S(9)=1
115 GOSUB 1000
120 PRINT "YOUR MOVE";
121 INPUT M1,M2
122 IF M1=INT(M1)AND M2=INT(M2)AND M1>0 AND M1<10 AND M2>0 AND M2<10 THEN 130
123 PRINT "ILLEGAL CO-ORDINATES."
124 GOTO 120
130 IF S(M1)=1 THEN 150
140 PRINT "ILLEGAL MOVE.": GOTO 120
150 IF S(M2)=1 THEN 140
160 IF M2-M1<>-3 AND S(M2)<>-1 THEN 140
170 IF M2>M1 THEN 140
180 IF M2-M1=-3 AND (S(M2)<>0) THEN 140
185 IF M2-M1<-4 THEN 140
186 IF M1=7 AND M2=3 THEN 140
190 S(M1)=0
200 S(M2)=1
205 GOSUB 1000
210 IF S(1)=1 OR S(2)=1 OR S(3)=1 THEN 820
220 FOR I=1 TO 9
221 IF S(I)=-1 THEN 230
222 NEXT I
223 GOTO 820
230 FOR I=1 TO 9
240 IF S(I)<>-1 THEN 330
250 IF S(I+3)=0 THEN 350
260 IF FNR(I)=I THEN 320
270 IF I>3 THEN 300
280 IF S(5)=1 THEN 350
290 GOTO 330
300 IF S(8)=1 THEN 350
310 GOTO 330
320 IF S(I+2)=1 OR S(I+4)=1 THEN 350
330 NEXT I
340 GOTO 820
350 FOR I=1 TO 19
360 FOR J=1 TO 3
370 FOR K=3 TO 1 STEP -1
380 T((J-1)*3+K)=B(I,(J-1)*3+4-K)
390 NEXT K
400 NEXT J
410 FOR J=1 TO 9
420 IF S(J)<>B(I,J) THEN 460
430 NEXT J
440 R=0
450 GOTO 540
460 FOR J=1 TO 9
470 IF S(J)<>T(J) THEN 510
480 NEXT J
490 R=1
500 GOTO 540
510 NEXT I
511 REM EMBER THE TERMINATION OF THIS LOOP IS IMPOSSIBLE
512 PRINT "ILLEGAL BOARD PATTERN."
530 STOP
540 X=I
550 FOR I=1 TO 4
560 IF M(X,I)<>0 THEN 600
570 NEXT I
580 PRINT "I RESIGN."
590 GOTO 820
600 Y=INT(RND(1)*4+1)
601 IF M(X,Y)=0 THEN 600
610 IF R<>0 THEN 630
620 PRINT "I MOVE FROM ";STR$(INT(M(X,Y)/10));" TO ";STR$(FNM(M(X,Y)))
622 S(INT(M(X,Y)/10))=0
623 S(FNM(M(X,Y)))=-1
624 GOTO 640
630 PRINT "I MOVE FROM ";STR$(FNR(INT(M(X,Y)/10)));" TO ";
631 PRINT STR$(FNR(FNM(M(X,Y))))
632 S(FNR(INT(M(X,Y)/10)))=0
633 S(FNR(FNM(M(X,Y))))=-1
640 GOSUB 1000
641 IF S(7)=-1 OR S(8)=-1 OR S(9)=-1 THEN 870
650 FOR I=1 TO 9
660 IF S(I)=1 THEN 690
670 NEXT I
680 GOTO 870
690 FOR I=1 TO 9
700 IF S(I)<>1 THEN 790
710 IF S(I-3)=0 THEN 120
720 IF FNR(I)=I THEN 780
730 IF I<7 THEN 760
740 IF S(5)=-1 THEN 120
750 GOTO 790
760 IF S(2)=-1 THEN 120
770 GOTO 790
780 IF S(I-2)=-1 OR S(I-4)=-1 THEN 120
790 NEXT I
800 PRINT "YOU CAN'T MOVE, SO ";
810 GOTO 870
820 PRINT "YOU WIN."
830 M(X,Y)=0
840 L=L+1
850 IF L+W=1 AND W=1 THEN PRINT "I WIN THE FIRST GAME." ELSE IF L+W=1 AND L=1 

    THEN PRINT "YOU WIN THE FIRST GAME." ELSE 

    PRINT "I HAVE WON";W;"AND YOU";L;"OUT OF";L+W;"GAMES."
851 PRINT
860 GOTO 100
870 PRINT "I WIN."
880 W=W+1
890 GOTO 850
900 DATA -1,-1,-1,1,0,0,0,1,1,-1,-1,-1,0,1,0,1,0,1
905 DATA -1,0,-1,-1,1,0,0,0,1,0,-1,-1,1,-1,0,0,0,1
910 DATA -1,0,-1,1,1,0,0,1,0,-1,-1,0,1,0,1,0,0,1
915 DATA 0,-1,-1,0,-1,1,1,0,0,0,-1,-1,-1,1,1,1,0,0
920 DATA -1,0,-1,-1,0,1,0,1,0,0,-1,-1,0,1,0,0,0,1
925 DATA 0,-1,-1,0,1,0,1,0,0,-1,0,-1,1,0,0,0,0,1
930 DATA 0,0,-1,-1,-1,1,0,0,0,-1,0,0,1,1,1,0,0,0
935 DATA 0,-1,0,-1,1,1,0,0,0,-1,0,0,-1,-1,1,0,0,0
940 DATA 0,0,-1,-1,1,0,0,0,0,0,-1,0,1,-1,0,0,0,0
945 DATA -1,0,0,-1,1,0,0,0,0
950 DATA 24,25,36,0,14,15,36,0,15,35,36,47,36,58,59,0
955 DATA 15,35,36,0,24,25,26,0,26,57,58,0
960 DATA 26,35,0,0,47,48,0,0,35,36,0,0,35,36,0,0
965 DATA 36,0,0,0,47,58,0,0,15,0,0,0
970 DATA 26,47,0,0,47,58,0,0,35,36,47,0,28,58,0,0,15,47,0,0
1000 PRINT
1010 FOR I=1 TO 3
1020 FOR J=1 TO 3
1030 PRINT TAB(10);MID$(P$,S((I-1)*3+J)+2,1);
1040 NEXT J
1050 PRINT
1060 NEXT I
1070 PRINT
1080 RETURN
2000 PRINT: PRINT "THIS PROGRAM PLAYS THE GAME OF HEXAPAWN."
2010 PRINT "HEXAPAWN IS PLAYED WITH CHESS PAWNS ON A 3 BY 3 BOARD."
2020 PRINT "THE PAWNS ARE MOVED AS IN CHESS - ONE SPACE FORWARD TO"
2030 PRINT "AN EMPTY SPACE OR ONE SPACE FORWARD AND DIAGONALLY TO"
2040 PRINT "CAPTURE AN OPPOSING MAN.  ON THE BOARD, YOUR PAWNS"
2050 PRINT "ARE 'O', THE COMPUTER'S PAWNS ARE 'X', AND EMPTY "
2060 PRINT "SQUARES ARE '.'.  TO ENTER A MOVE, TYPE THE NUMBER OF"
2070 PRINT "THE SQUARE YOU ARE MOVING FROM, FOLLOWED BY THE NUMBER"
2080 PRINT "OF THE SQUARE YOU WILL MOVE TO.  THE NUMBERS MUST BE"
2090 PRINT "SEPERATED BY A COMMA.": PRINT
2100 PRINT "THE COMPUTER STARTS A SERIES OF GAMES KNOWING ONLY WHEN"
2105 PRINT "THE GAME IS WON (A DRAW IS IMPOSSIBLE) AND HOW TO MOVE."
2110 PRINT "IT HAS NO STRATEGY AT FIRST AND JUST MOVES RANDOMLY."
2120 PRINT "HOWEVER, IT LEARNS FROM EACH GAME.  THUS, WINNING BECOMES"
2130 PRINT "MORE AND MORE DIFFICULT.  ALSO, TO HELP OFFSET YOUR"
2140 PRINT "INITIAL ADVANTAGE, YOU WILL NOT BE TOLD HOW TO WIN THE"
2150 PRINT "GAME BUT MUST LEARN THIS BY PLAYING."
2160 PRINT: PRINT "THE NUMBERING OF THE BOARD IS AS FOLLOWS:"
2170 PRINT TAB(10);"123": PRINT TAB(10);"456": PRINT TAB(10);"789"
2180 PRINT: PRINT "FOR EXAMPLE, TO MOVE YOUR RIGHTMOST PAWN FORWARD,"
2190 PRINT "YOU WOULD TYPE 9,6 IN RESPONSE TO THE QUESTION"
2200 PRINT "'YOUR MOVE ?'.  SINCE I'M A GOOD SPORT, YOU'LL ALWAYS"
2210 PRINT "GO FIRST.": PRINT
2220 GOTO 100
9999 END
