10 ' NUMBER SQUARE GAME 20 ' VER 4.0 - 12 NOV 79 30 ' MARC I. LEAVEY, M.D. 40 ROW=0 ' Was LINE - conflict with MBASIC 50 DIGITS=0 60 PRINT "N U M B E R S Q U A R E S" 70 PRINT "---------------------------" 80 PRINT 90 PRINT "WELCOME TO THE WORLD OF" 100 PRINT "CONFUSION. THERE ARE TWO" 110 PRINT "VERSIONS OF NUMBER SQUARES:" 120 PRINT " 1 - SEQUENTIAL" 130 PRINT " 2 - MAGIC SQUARE" 140 INPUT "WHICH IS YOUR PLEASURE ",T 150 IF T=1 GOTO 310 160 IF T<>2 GOTO 140 170 ' 180 ' SET UP MAGIC 190 ' SQUARE BOARD 200 ' 210 FOR I=1 TO 4 220 FOR J=1 TO 4 230 READ M(I,J) 240 B(I,J)=M(I,J) 250 NEXT J 260 NEXT I 270 DATA 1,6,15,8,12,11,2,5,10,13,4,3,7,16,9,14 280 I1=4 290 J1=2 300 GOTO 440 310 ' 320 ' SET UP SEQUENTIAL 330 ' BOARD 340 ' 350 DIM B(4,4) 360 FOR I=1 TO 4 370 FOR J=1 TO 4 380 B(I,J)=(I-1)*4+J 390 NEXT J 400 NEXT I 410 I1=4 420 J1=4 430 ' 440 ' NOW SCRAMBLE THE BOARD 450 ' TWO HUNDRED TIMES 460 ' 470 PRINT "I AM NOW SCRAMBLING THE BOARD..." 480 FOR Q=1 TO 200 490 M=INT(1+RND*4) 500 ON M GOTO 510,560,610,660 510 IF I1=1 GOTO 490 520 B(I1,J1)=B(I1-1,J1) 530 B(I1-1,J1)=16 540 I1=I1-1 550 GOTO 700 560 IF I1=4 GOTO 490 570 B(I1,J1)=B(I1+1,J1) 580 B(I1+1,J1)=16 590 I1=I1+1 600 GOTO 700 610 IF J1=1 GOTO 490 620 B(I1,J1)=B(I1,J1-1) 630 B(I1,J1-1)=16 640 J1=J1-1 650 GOTO 700 660 IF J1=4 GOTO 490 670 B(I1,J1)=B(I1,J1+1) 680 B(I1,J1+1)=16 690 J1=J1+1 700 NEXT Q 710 ' 720 ' PRINT BOARD 730 ' 740 M9=0 750 ' OUTPUT A "HOME UP" 760 ' PRINT CHR$(16); 770 PRINT "-----------------" 780 FOR I=1 TO 4 790 FOR J=1 TO 4 800 PRINT ": "; 810 IF B(I,J)=16 THEN PRINT " ";:GOTO 840 820 ' IF B(I,J)<10 THEN PRINT " "; 830 PRINT USING"##";B(I,J); 840 NEXT J 850 PRINT ":" 860 PRINT "-----------------" 870 NEXT I 880 ' 890 ' ERASE REST OF SCREEN AND 900 ' BEEP FOR INPUT 910 ' 920 ' PRINT CHR$(22);CHR$(7);CHR$(7); 930 ' 940 ' INPUT MOVE 950 ' 960 INPUT "MOVE WHICH PIECE ",M 970 I1=0:J1=0 980 FOR I=1 TO 4 990 FOR J=1 TO 4 1000 IF B(I,J)=M THEN I1=I:J1=J 1010 NEXT J 1020 NEXT I 1030 IF I1=0 THEN PRINT "I CAN'T FIND THAT NUMBER":GOTO 940 1040 I2=0:J2=0 1050 FOR I=I1-1 TO I1+1 1060 IF I>4 GOTO 1090 1070 IF I<1 GOTO 1090 1080 IF B(I,J1)=16 THEN I2=I:J2=J1:GOTO 1170 1090 NEXT I 1100 FOR J=J1-1 TO J1+1 1110 IF J>4 GOTO 1140 1120 IF J<1 GOTO 1140 1130 IF B(I1,J)=16 THEN I2=I1:J2=J:GOTO 1170 1140 NEXT J 1150 M9=M9+1 1160 PRINT "NOT A VALID MOVE":GOTO 940 1170 B(I2,J2)=M 1180 B(I1,J1)=16 1190 ON T GOTO 1210,1320 1200 ' 1210 ' SEQUENTIAL SOLUTION 1220 ' 1230 C=0 1240 FOR I=1 TO 4 1250 FOR J=1 TO 4 1260 IF B(I,J)M(I,J) GOTO 720 1390 NEXT J 1400 NEXT I 1410 ' 1420 ' A WIN IS DECLARED! 1430 ' 1440 PRINT "THAT IS THE CORRECT SOLUTION!" 1450 INPUT "LIKE TO PLAY ANOTHER GAME",I$ 1460 IF LEFT$(I$,1)="Y" THEN RUN 1470 END