Dieses BASIC Programm für den HP-85 berechnet eine Springertour auf einem Schachbrett. Das Startfeld kann beliebig gewählt werden.
HP-85 Knight’s Tour BASIC Programm:
1000 ! KNIGHT'S TOUR 1010 ! (C) 2004 J. Keller 1020 ! 1030 OPTION BASE 1 1040 INTEGER B(8,8),X(8),Y(8) 1050 INTEGER I,J,K,M,C,F,U,V 1060 GOSUB 4000 1070 ! 1080 CLEAR @ DISP 1090 DISP " _/| KNIGHT'S TOUR |\_" 1100 DISP " // o\ on a chessboard /o \\" 1110 DISP " || ._) solved with (_. ||" 1120 DISP " //__\ Warnsdorff's /__\\" 1130 DISP " )___( ____ rule ____ )___(" 1140 DISP 1150 DISP "Start position"; 1160 INPUT S$@ DISP 1170 IF LEN(S$)<>2 THEN 1140 1180 I=NUM(S$[1,1])-96 1190 J=NUM(S$[2,2])-48 1200 IF I<0 THEN I=NUM(S$[1,1])-64 1210 IF I<1 OR I>8 THEN 1140 1220 IF J<1 OR J>8 THEN 1140 1500 ! 1510 ! MAIN LOOP 1520 ! 1530 DISP "Wait a moment ..." 1540 B(I,J)=-1 @ GOSUB 3000 1550 FOR M=2 TO 64 1560 GOSUB 2000 1570 IF F=0 THEN 5000 1580 I=I+X(F) @ J=J+Y(F) 1590 B(I,J)=-M @ GOSUB 3000 1600 NEXT M 1650 ! 1660 ! DISPLAY SOLUTION 1670 ! 1680 CLEAR 1690 FOR J=8 TO 1 STEP -1 1700 DISP CHR$(48+J);"|"; 1710 FOR I=1 TO 8 1720 C=-B(I,J) 1730 U=48+INT(C/10) 1740 V=48+C MOD 10 1750 IF U=48 THEN U=32 1760 DISP " ";CHR$(U);CHR$(V); 1770 NEXT I 1780 DISP 1790 NEXT J 1800 DISP " +------------------------" 1810 DISP " a b c d e f g h" 1820 GOTO 6000 1985 ! 1990 ! FIND NEXT MOVE 1995 ! 2000 C=10 @ F=0 2010 FOR K=1 TO 8 2020 U=I+X(K) 2030 IF U<1 OR U>8 THEN 2090 2040 V=J+Y(K) 2050 IF V<1 OR V>8 THEN 2090 2060 D=B(U,V) 2070 IF D<0 THEN 2090 2080 IF D8 THEN 3080 3030 V=J+Y(K) 3040 IF V<1 OR V>8 THEN 3080 3050 C=B(U,V) 3060 IF C<0 THEN 3080 3070 B(U,V)=C-1 3080 NEXT K 3090 RETURN 3985 ! 3990 ! INITIALIZATION 3995 ! 4000 FOR K=1 TO 8 4010 READ X(K),Y(K) 4020 NEXT K 4030 ! 4040 FOR J=1 TO 8 4050 FOR I=1 TO 8 4060 READ B(I,J) 4070 NEXT I 4080 NEXT J 4090 ! 4100 RETURN 4110 ! 4120 ! MOVE CODES 4130 ! 4140 DATA 1,2 4150 DATA 2,1 4160 DATA 2,-1 4170 DATA 1,-2 4180 DATA -1,-2 4190 DATA -2,-1 4200 DATA -2,1 4210 DATA -1,2 4220 ! 4230 ! SQUARE CODES 4240 ! 4250 DATA 2,3,4,4,4,4,3,2 4260 DATA 3,4,6,6,6,6,4,3 4270 DATA 4,6,8,8,8,8,6,4 4280 DATA 4,6,8,8,8,8,6,4 4290 DATA 4,6,8,8,8,8,6,4 4300 DATA 4,6,8,8,8,8,6,4 4310 DATA 3,4,6,6,6,6,4,3 4320 DATA 2,3,4,4,4,4,3,2 4985 ! 4990 ! SHOULD NOT HAPPEN 4995 ! 5000 DISP "No solution found!" 5995 ! 6000 END
1 Kommentar