5 PRINT TAB(33);"BATTLE"
7 PRINT TAB(15);"CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY"
10 REM -- BATTLE WRITTEN BY RAY WESTERGARD  10/70
20 REM COPYRIGHT 1971 BY THE REGENTS OF THE UNIV. OF CALIF.
30 REM PRODUCED AT THE LAWRENCE HALL OF SCIENCE, BERKELEY
40 DIM FF(6,6),HH(6,6),AA(4),BB(4),CC(6),LL(4)
50 FOR X=1 TO 6
51 FOR Y=1 TO 6
52 FF(X,Y)=0
53 NEXT Y
54 NEXT X
60 FOR I=1 TO 3
70 N=4-I
80 FOR J=1 TO 2
90 A=INT(6*RND(1)+1)
100 B=INT(6*RND(1)+1)
110 D=INT(4*RND(1)+1)
120 IF FF(A,B)>0 THEN 90
130 M=0
140 ON D GOTO 150,340,550,740
150 BB(1)=B
160 BB(2)=7:BB(3)=7
170 FOR K=1 TO N
180 IF M>1 THEN 240
190 IF BB(K)=6 THEN 230
200 IF FF(A,BB(K)+1)>0 THEN 230
210 BB(K+1)=BB(K)+1
220 GOTO 280
230 M=2
240 IF BB(1)<BB(2) AND BB(1)<BB(3) THEN Z=BB(1)
242 IF BB(2)<BB(1) AND BB(2)<BB(3) THEN Z=BB(2)
244 IF BB(3)<BB(1) AND BB(3)<BB(2) THEN Z=BB(3)
250 IF Z=1 THEN 90
260 IF FF(A,Z-1)>0 THEN 90
270 BB(K+1)=Z-1
280 NEXT K
290 FF(A,B)=9-2*I-J
300 FOR K=1 TO N
310 FF(A,BB(K+1))=FF(A,B)
320 NEXT K
330 GOTO 990
340 AA(1)=A
350 BB(1)=B
360 AA(2)=0:AA(3)=0:BB(2)=0:BB(3)=0
370 FOR K=1 TO N
380 IF M>1 THEN 460
390 IF AA(K)=1 OR BB(K)=1 THEN 450
400 IF FF(AA(K)-1,BB(K)-1)>0 THEN 450
410 IF FF(AA(K)-1,BB(K))>0 AND FF(AA(K)-1,BB(K))=FF(AA(K),BB(K)-1) THEN 450
420 AA(K+1)=AA(K)-1
430 BB(K+1)=BB(K)-1
440 GOTO 530
450 M=2
460 IF AA(1)>AA(2) AND AA(1)>AA(3) THEN Z1=AA(1)
462 IF AA(2)>AA(1) AND AA(2)>AA(3) THEN Z1=AA(2)
464 IF AA(3)>AA(1) AND AA(3)>AA(2) THEN Z1=AA(3)
470 IF BB(1)>BB(2) AND BB(1)>BB(3) THEN Z2=BB(1)
474 IF BB(2)>BB(1) AND BB(2)>BB(3) THEN Z2=BB(2)
476 IF BB(3)>BB(1) AND BB(3)>BB(2) THEN Z2=BB(3)
480 IF Z1=6 OR Z2=6 THEN 90
490 IF FF(Z1+1,Z2+1)>0 THEN 90
500 IF FF(Z1,Z2+1)>0 AND FF(Z1,Z2+1)=FF(Z1+1,Z2) THEN 90
510 AA(K+1)=Z1+1
520 BB(K+1)=Z2+1
530 NEXT K
540 GOTO 950
550 AA(1)=A
560 AA(2)=7:AA(3)=7
570 FOR K=1 TO N
580 IF M>1 THEN 640
590 IF AA(K)=6 THEN 630
600 IF FF(AA(K)+1,B)>0 THEN 630
610 AA(K+1)=AA(K)+1
620 GOTO 680
630 M=2
640 IF AA(1)<AA(2) AND AA(1)<AA(3) THEN Z=AA(1)
642 IF AA(2)<AA(1) AND AA(2)<AA(3) THEN Z=AA(2)
644 IF AA(3)<AA(1) AND AA(3)<AA(2) THEN Z=AA(3)
650 IF Z=1 THEN 90
660 IF FF(Z-1,B)>0 THEN 90
670 AA(K+1)=Z-1
680 NEXT K
690 FF(A,B)=9-2*I-J
700 FOR K=1 TO N
710 FF(AA(K+1),B)=FF(A,B)
720 NEXT K
730 GOTO 990
740 AA(1)=A
750 BB(1)=B
760 AA(2)=7:AA(3)=7
770 BB(2)=0:BB(3)=0
780 FOR K=1 TO N
790 IF M>1 THEN 870
800 IF AA(K)=6 OR BB(K)=1 THEN 860
810 IF FF(AA(K)+1,BB(K)-1)>0 THEN 860
820 IF FF(AA(K)+1,BB(K))>0 AND FF(AA(K)+1,BB(K))=FF(AA(K),BB(K)-1) THEN 860
830 AA(K+1)=AA(K)+1
840 BB(K+1)=BB(K)-1
850 GOTO 940
860 M=2
870 IF AA(1)<AA(2) AND AA(1)<AA(3) THEN Z1=AA(1)
872 IF AA(2)<AA(1) AND AA(2)<AA(3) THEN Z1=AA(2)
874 IF AA(3)<AA(1) AND AA(3)<AA(2) THEN Z1=AA(3)
880 IF BB(1)>BB(2) AND BB(1)>BB(3) THEN Z2=BB(1)
882 IF BB(2)>BB(1) AND BB(2)>BB(3) THEN Z2=BB(2)
884 IF BB(3)>BB(1) AND BB(3)>BB(2) THEN Z2=BB(3)
890 IF Z1=1 OR Z2=6 THEN 90
900 IF FF(Z1-1,Z2+1)>0 THEN 90
910 IF FF(Z1,Z2+1)>0 AND FF(Z1,Z2+1)=FF(Z1-1,Z2) THEN 90
920 AA(K+1)=Z1-1
930 BB(K+1)=Z2+1
940 NEXT K
950 FF(A,B)=9-2*I-J
960 FOR K=1 TO N
970 FF(AA(K+1),BB(K+1))=FF(A,B)
980 NEXT K
990 NEXT J
1000 NEXT I
1010 PRINT
1020 PRINT "THE FOLLOWING CODE OF THE BAD GUYS' FLEET DISPOSITION"
1030 PRINT "HAS BEEN CAPTURED BUT NOT DECODED:"
1040 PRINT
1050 FOR I=1 TO 6
1051 FOR J=1 TO 6
1052 HH(I,J)=FF(J,I)
1053 NEXT J
1054 NEXT I
1060 FOR I=1 TO 6
1061 FOR J=1 TO 6
1062 PRINT HH(I,J);
1063 NEXT J
1064 PRINT
1065 NEXT I
1070 PRINT
1080 PRINT "DE-CODE IT AND USE IT IF YOU CAN"
1090 PRINT "BUT KEEP THE DE-CODING METHOD A SECRET."
1100 PRINT
1110 FOR I=1 TO 6
1111 FOR J=1 TO 6
1112 HH(I,J)=0
1113 NEXT J
1114 NEXT I
1120 FOR I=1 TO 3
1121 LL(I)=0
1122 NEXT I
1130 CC(1)=2:CC(2)=2
1140 CC(3)=1:CC(4)=1
1150 CC(5)=0:CC(6)=0
1160 S=0:H=0
1170 PRINT "START GAME"
1180 INPUT X,Y
1185 IF X < 0 AND Y < 0 THEN END
1190 IF X<1 OR X>6 OR INT(X)<>ABS(X) THEN 1210
1200 IF Y>0 AND Y<7 AND INT(Y)=ABS(Y) THEN 1230
1210 PRINT "INVALID INPUT.  TRY AGAIN."
1220 GOTO 1180
1230 R=7-Y
1240 C=X
1250 IF FF(R,C)>0 THEN 1290
1260 S=S+1
1270 PRINT "SPLASH!  TRY AGAIN."
1280 GOTO 1180
1290 IF CC(FF(R,C))<4 THEN 1340
1300 PRINT "THERE USED TO BE A SHIP AT THAT POINT, BUT YOU SUNK IT."
1310 PRINT "SPLASH!  TRY AGAIN."
1320 S=S+1
1330 GOTO 1180
1340 IF HH(R,C)>0 THEN 1420
1350 H=H+1
1360 HH(R,C)=FF(R,C)
1370 PRINT "A DIRECT HIT ON SHIP NUMBER";FF(R,C)
1380 CC(FF(R,C))=CC(FF(R,C))+1
1390 IF CC(FF(R,C))>=4 THEN 1470
1400 PRINT "TRY AGAIN."
1410 GOTO 1180
1420 PRINT "YOU ALREADY PUT A HOLE IN SHIP NUMBER";FF(R,C);
1430 PRINT "AT THAT POINT."
1440 PRINT "SPLASH!  TRY AGAIN."
1450 S=S+1
1460 GOTO 1180
1470 LL((INT(FF(R,C)-1)/2)+1)=LL((INT(FF(R,C)-1)/2)+1)+1
1480 PRINT "AND YOU SUNK IT.  HURRAH FOR THE GOOD GUYS."
1490 PRINT "SO FAR, THE BAD GUYS HAVE LOST"
1500 PRINT LL(1);"DESTROYER(S),";LL(2);"CRUISER(S), AND";
1510 PRINT LL(3);"AIRCRAFT CARRIER(S)."
1520 PRINT "YOUR CURRENT SPLASH/HIT RATIO IS";S/H
1530 IF (LL(1)+LL(2)+LL(3))<6 THEN 1180
1540 PRINT
1550 PRINT "YOU HAVE TOTALLY WIPED OUT THE BAD GUYS' FLEET"
1560 PRINT "WITH A FINAL SPLASH/HIT RATIO OF";S/H
1570 IF S/H>0 THEN 1590
1580 PRINT "CONGRATULATIONS -- A DIRECT HIT EVERY TIME."
1590 PRINT
1600 PRINT "****************************"
1610 PRINT
1620 GOTO 50
1630 END
