Appears on
Assembled by Tim Ward from many sources. Contains programs 10252 – 10293.
Source Code
3 DIM B(8) 5 DIM A(16) 10 GOSUB 300 15 LET M=0 20 FOR I=1 TO 16 30 LET A(I)=0 40 NEXT I 50 FOR I=1 TO 16 60 LET R=INT (RND*16)+1 70 IF NOT A(R)=0 THEN GOTO 60 80 LET A(R)=I 90 NEXT I 100 GOSUB 500 110 IF F=1 THEN GOTO 20 120 GOSUB 600 130 PRINT 140 PRINT "YOUR MOVE" 150 INPUT X 152 LET C=X 155 IF X=0 THEN STOP 160 GOSUB 400 170 GOSUB 700 180 IF NOT F=0 THEN GOTO 210 185 PRINT 190 PRINT C;" IS AN ILLEGAL MOVE,RE-ENTER" 200 GOTO 150 210 LET A(X+F)=A(X) 220 LET A(X)=16 230 GOTO 800 240 LET M=M+1 250 GOTO 120 300 LET B(1)=2 310 LET B(2)=4 320 LET B(3)=5 330 LET B(4)=7 340 LET B(5)=10 350 LET B(6)=12 360 LET B(7)=13 370 LET B(8)=15 380 RETURN 390 REM CONVERT NO.TO LOCATION IN ARRAY 400 FOR I=1 TO 16 410 IF A(I)=X THEN GOTO 430 420 NEXT I 430 LET X=I 440 RETURN 450 REM VERIFY SOLUTION POSSIBLE 500 LET F=1 510 LET S=0 520 FOR I=1 TO 15 530 FOR J=I+1 TO 16 540 IF A(I)>A(J) THEN LET S=S+1 550 NEXT J 560 NEXT I 565 FOR I=1 TO 8 570 IF A(B(I))=16 THEN LET S=S+1 575 NEXT I 585 IF (S/2)*2=S THEN LET F=0 590 RETURN 595 REM DISPLAY GAME BOARD 600 CLS 610 PRINT ,"FIFTEEN PUZZLE" 615 PRINT 620 LET I=1 625 PRINT , 630 FOR Y=1 TO 4 632 IF A(I)<10 THEN PRINT " "; 635 IF A(I)=16 THEN PRINT " "; 640 IF NOT A(I)=16 THEN PRINT A(I); 645 PRINT " "; 650 LET I=I+1 655 NEXT Y 660 PRINT 662 PRINT 665 IF I=17 THEN RETURN 670 GOTO 625 680 REM CHECK FOR LEGAL MOVE 700 LET F=0 710 IF X+1>16 THEN GOTO 725 720 IF A(X+1)=16 THEN LET F=1 725 IF X-1<0 OR X-1=0 THEN GOTO 735 730 IF A(X-1)=16 THEN LET F=-1 735 IF X+4>16 THEN GOTO 745 740 IF A(X+4)=16 THEN LET F=4 745 IF X-4<0 OR X-4=0 THEN GOTO 760 750 IF A(X-4)=16 THEN LET F=-4 760 RETURN 770 REM CHECK FOR WIN 800 FOR I=1 TO 16 810 IF NOT A(I)=I THEN GOTO 240 820 NEXT I 830 GOSUB 600 840 PRINT 850 PRINT 860 PRINT "YOU WON IN ONLY";M;"MOVES" 870 STOP 880 CLEAR 890 SAVE "1026%5" 900 RUN