Advertisement
przemko

Knight's Tour

Dec 7th, 2024 (edited)
38
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PureBasic 3.44 KB | Source Code | 0 0
  1. 1000 REM WELCOME
  2. 1010 GRAPHICS 5
  3. 1020 POKE 752,1
  4. 1030 ? :? "            KNIGHT'S TOUR"
  5. 1040 ? "    (C) PRZEMYSLAW KOBYLANSKI 2024"
  6. 1050 REM BOARD
  7. 1060 Y=0
  8. 1070 FOR I=0 TO 7
  9. 1080 FOR K=0 TO 3
  10. 1090 X=0
  11. 1100 FOR J=0 TO 7
  12. 1110 SUM=I+J
  13. 1120 MOD=SUM-2*INT(SUM/2)
  14. 1130 COLOR 2+MOD
  15. 1140 PLOT X,Y
  16. 1150 DRAWTO X+3,Y
  17. 1160 X=X+4
  18. 1170 NEXT J
  19. 1180 Y=Y+1
  20. 1190 NEXT K
  21. 1200 NEXT I
  22. 1210 GOSUB 4000
  23. 1220 REM ARRAYS
  24. 1230 DIM B(7,7),C(7,7),DX(7),DY(7),S(63,8),Z(63,7),S$(130),A$(1)
  25. 1240 SP=0
  26. 1250 FOR J=0 TO 7
  27. 1260 FOR I=0 TO 7
  28. 1270 B(I,J)=0
  29. 1280 READ V
  30. 1290 C(I,J)=V
  31. 1300 NEXT I
  32. 1310 NEXT J
  33. 1320 FOR I=0 TO 7
  34. 1330 READ X,Y
  35. 1340 DX(I)=X
  36. 1350 DY(I)=Y
  37. 1360 NEXT I
  38. 1370 REM START SEARCHING
  39. 1400 N=1
  40. 1410 X=0
  41. 1420 Y=0
  42. 1430 GOTO 2000
  43. 1440 ? S$;" PRESS ENTER";
  44. 1450 INPUT A$
  45. 1460 POKE 53277,0
  46. 1470 GRAPHICS 0
  47. 1480 END
  48. 2000 REM SEARCH
  49. 2010 S$(2*N-1)=CHR$(65+X)
  50. 2020 S$(2*N)=CHR$(56-Y)
  51. 2030 B(X,Y)=N
  52. 2040 COLOR 1
  53. 2050 FOR I=1 TO 2
  54. 2060 FOR J=1 TO 2
  55. 2070 PLOT 4*X+I,4*Y+J
  56. 2080 NEXT J
  57. 2090 NEXT I
  58. 2100 IF N=64 THEN 1440
  59. 2110 N=N+1
  60. 2120 D=-1
  61. 2130 GOSUB 3000
  62. 2140 FOR I=0 TO 7
  63. 2150 X1=X+DX(I)
  64. 2160 Y1=Y+DY(I)
  65. 2170 TRAP 2200
  66. 2180 S(SP,I)=C(X1,Y1)
  67. 2190 GO O 2210
  68. 2190 GOTO 2210
  69. 2200 S(SP,I)=9999
  70. 2210 Z(SP,I)=I
  71. 2220 NEXT I
  72. 2230 FOR I=6 TO 0 STEP -1
  73. 2240 FOR J=0 TO I
  74. 2250 IF S(SP,J)<=S(SP,J+1) THEN 2320
  75. 2260 TEMP=S(SP,J)
  76. 2270 S(SP,J)=S(SP,J+1)
  77. 2280 S(SP,J+1)=TEMP
  78. 2290 TEMP=Z(SP,J)
  79. 2300 Z(SP,J)=Z(SP,J+1)
  80. 2310 Z(SP,J+1)=TEMP
  81. 2320 NEXT J
  82. 2330 NEXT I
  83. 2340 REM LOOK AROUND
  84. 2350 S(SP,8)=0
  85. 2360 IF S(SP,S(SP,8))>8 THEN 2590
  86. 2370 I=Z(SP,S(SP,8))
  87. 2380 D1=DX(I)
  88. 2390 D2=DY(I)
  89. 2400 X=X+D1
  90. 2410 Y=Y+D2
  91. 2420 IF B(X,Y)>0 THEN 2520
  92. 2430 A1=P0+16+8*Y
  93. 2440 A0=A1-D2*8
  94. 2445 POKE 53248,48+8*X
  95. 2450 FOR I=0 TO 7
  96. 2460 POKE A1+I,PEEK(A0+I)
  97. 2480 POKE A0+I,0
  98. 2490 NEXT I
  99. 2492 SOUND 0,9,14,100
  100. 2494 FOR D=1 TO 4
  101. 2496 NEXT D
  102. 2498 SOUND 0,0,0,0
  103. 2500 SP=SP+1
  104. 2510 GOTO 2000
  105. 2520 I=Z(SP,S(SP,8))
  106. 2530 D1=DX(I)
  107. 2540 D2=DY(I)
  108. 2550 X=X-D1
  109. 2560 Y=Y-D2
  110. 2570 S(SP,8)=S(SP,8)+1
  111. 2580 IF S(SP,8)<8 THEN 2360
  112. 2590 REM BACKTRACK
  113. 2600 S$(2*N-1,2*N)=" "
  114. 2610 SUM=X+Y
  115. 2620 MOD=SUM-2*INT(SUM/2)
  116. 2630 COLOR 2+MOD
  117. 2640 FOR I=1 TO 2
  118. 2650 FOR J=1 TO 2
  119. 2660 PLOT 4*X+I,4*Y+J
  120. 2670 NEXT J
  121. 2680 NEXT I
  122. 2690 B(X,Y)=0
  123. 2700 D=1
  124. 2710 GOSUB 3000
  125. 2720 N=N-1
  126. 2730 SP=SP-1
  127. 2740 IF SP=0 THEN 1440
  128. 2750 I=Z(SP,S(SP,8))
  129. 2760 D1=DX(I)
  130. 2770 D2=DY(I)
  131. 2780 X1=X-D1
  132. 2790 Y1=Y-D2
  133. 2800 POKE 53248,48+8*X1
  134. 2810 1 0 16 8 1
  135. 2810 A1=P0+16+8*Y1
  136. 2820 A0=P0+16+8*Y
  137. 2830 FOR I=0 TO 7
  138. 2840 POKE A1+I,PEEK(A0+I)
  139. 2850 POKE A0+I,0
  140. 2860 NEXT I
  141. 2862 SOUND 0,100,14,100
  142. 2864 FOR D=1 TO 2
  143. 2866 NEXT D
  144. 2868 SOUND 0,0,0,0
  145. 2890 GOTO 2520
  146. 3000 REM UPDATE COUNTERS
  147. 3010 FOR I=0 TO 7
  148. 3020 X1=X+DX(I)
  149. 3030 Y1=Y+DY(I)
  150. 3040 TRAP 3060
  151. 3050 C(X1,Y1)=C(X1,Y1)+D
  152. 3060 NEXT I
  153. 3070 RETURN
  154. 4000 REM PREPAIR SPRITE
  155. 4010 TOP=156
  156. 4020 POKE 106,TOP
  157. 4030 PB=TOP*256
  158. 4040 POKE 54279,TOP
  159. 4050 POKE 559,46
  160. 4060 POKE 623,1
  161. 4070 POKE 704,223
  162. 4080 POKE 53248,48
  163. 4090 POKE 53256,0
  164. 4100 P0=PB+512
  165. 4110 FOR A=P0 TO P0+127
  166. 4120 POKE A,0
  167. 4130 NEXT A
  168. 4140 FOR A=P0+16 TO P0+23
  169. 4150 READ V
  170. 4160 POKE A,V
  171. 4170 NEXT A
  172. 4180 POKE 53277,3
  173. 4190 RETURN
  174. 5000 REM BITMAP
  175. 5110 DATA 16,56,92,252,238,78,30,63
  176. 6000 REM COUNTERS
  177. 6010 DATA 2,3,4,4,4,4,3,2
  178. 6020 DATA 3,4,6,6,6,6,4,3
  179. 6030 DATA 4,6,8,8,8,8,6,4
  180. 6040 DATA 4,6,8,8,8,8,6,4
  181. 6050 DATA 4,6,8,8,8,8,6,4
  182. 6060 DATA 4,6,8,8,8,8,6,4
  183. 6070 DATA 3,4,6,6,6,6,4,3
  184. 6080 DATA 2,3,4,4,4,4,3,2
  185. 7000 REM DX & DY
  186. 7010 DATA 1,-2,2,-1,2,1,1,2,-1,2,-2,1,-2,-1,-1,-2
Tags: basic Chess Atari
Advertisement
Comments
  • przemko
    14 days (edited)
    Comment was deleted
Add Comment
Please, Sign In to add comment
Advertisement