10
20
30
40 :
50 MODE 8
60 VDU23,1,0;0;0;0;
70 PRINTTAB(0,20)"SEARCH LEVEL: 12345678"
80 PRINTTAB(13,21)"T B";
90 DIM G%(8)
100 S%=0
110 PX%=0:PY%=0
120 B$=STRING$(4,CHR$17+CHR$128+" "+CHR$17+CHR$139+CHR$17+CHR$11+"#")
130 W$=STRING$(4,CHR$17+CHR$139+CHR$17+CHR$11+"#"+CHR$17+CHR$128+" ")
140 T%=TIME
150 PROCSCAN_ROW(1)
160 T%=TIME-T%
170 MIN%=T%DIV6000:SEC%=(T%MOD6000)DIV100
180 PRINTTAB(0,20);S%;" solutions found in ";MIN%;"mins ";SEC%;"secs"
190 PRINTTAB(13,21)" ";
200 VDU31,0,21
210 VDU23,1,1;0;0;0;
220 END
230 :
240 DEFPROCSCAN_ROW(Y%)
250 COLOUR 128:COLOUR 7:PRINTTAB(Y%+13,21)"=";
260 IF Y%=8 THEN PRINTTAB(21,19)"*"
270 LOCAL X%
280 X%=0
290 REPEAT
300 REPEAT
310 X%=X%+1
320 C%=TRUE:PROCSCAN_COLUMN
330 UNTIL C% OR X%=8
340 IF NOT C% THEN 380
350 G%(Y%)=X%
360 IF Y%=8 THEN S%=S%+1:PROCSHOW_SOLUTION ELSE PROCSCAN_ROW(Y%+1)
370 G%(Y%)=0
380 UNTIL X%=8
390 COLOUR 128:COLOUR 7:PRINTTAB(Y%+13,21)" ";
400 IF Y%=8 THEN PRINTTAB(21,19)" "
410 ENDPROC
420 :
430 DEFPROCSCAN_COLUMN
440 IF G%(Y%) THEN C%=FALSE ELSE PROCSCAN_DIAGONAL
450 ENDPROC
460 :
470 DEFPROCSCAN_DIAGONAL
480 FOR YY%=1 TO 8
490 IF G%(YY%)=X% THEN C%=FALSE
500 NEXT
510 IF C%=TRUE THEN PROCSCAN_NW_DIAGONAL
520 ENDPROC
530 :
540 DEFPROCSCAN_NW_DIAGONAL
550 XX%=X%:YY%=Y%
560 REPEAT
570 IF G%(YY%)=XX% THEN C%=FALSE
580 XX%=XX%-1:YY%=YY%-1
590 UNTIL XX%=0 OR YY%=0
600 XX%=X%+1:YY%=Y%+1
610 IF C%=FALSE THEN ENDPROC
620 IF XX%=9 OR YY%=9 THEN 670
630 REPEAT
640 IF G%(YY%)=XX% THEN C%=FALSE
650 XX%=XX%+1:YY%=YY%+1
660 UNTIL XX%=9 OR YY%=9
670 IF C%=TRUE THEN PROCSCAN_NE_DIAGONAL
680 ENDPROC
690 :
700 DEFPROCSCAN_NE_DIAGONAL
710 XX%=X%:YY%=Y%
720 REPEAT
730 IF G%(YY%)=XX% THEN C%=FALSE
740 XX%=XX%+1:YY%=YY%-1
750 UNTIL XX%=9 OR YY%=0
760 XX%=X%-1:YY%=Y%-1
770 IF C%=FALSE OR XX%=0 OR YY%=9 THEN ENDPROC
780 REPEAT
790 IF G%(YY%)=XX% THEN C%=FALSE
800 XX%=XX%-1:YY%=YY%+1
810 UNTIL XX%=0 OR YY%=9
820 ENDPROC
830 :
840 DEFPROCSHOW_SOLUTION
850 bx%=PX%*10:by%=PY%*10
860 COLOUR 128:COLOUR 11:PRINTTAB(bx%,by%);S%;
870 FOR YY%=1 TO 8
880 PRINTTAB(bx%,by%+YY%);
890 IF YY% AND 1 THEN PRINT W$; ELSE PRINT B$;
900 IF G%(YY%) THEN Q%=(((by%+YY%) AND 1) EOR ((bx%+G%(YY%)) AND 1))
910 IF G%(YY%) THEN COLOUR 139-11*Q%:COLOUR 11*Q%:PRINT TAB(bx%+G%(YY%)-1,by%+YY%)"Q";
920 NEXT
930 PX%=PX%+1:IF PX%=8 THEN PX%=0:PY%=PY%+1:IF PY%=2 THEN PY%=0
940 ENDPROC