Advertisement
przemko

Knight's Tour

Dec 7th, 2024
3,480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PureBasic 2.02 KB | Source Code | 0 0
  1. 10 GR : PR# 3: PRINT TAB( 34)"KNIGHT´S TOUR": PRINT TAB(25)"(C) PRZEMYSLAW KOBYLANSKI 2024"
  2. 20 Y = 0: FOR I = 0 TO 7: FOR K = 1 TO 4: FOR J = 0 TO 7:X = 3 * J:SUM = I + J:MOD = SUM - 2 * INT (SUM / 2): COLOR= 7 - 5 * MOD: HLIN X,X + 2 AT Y: NEXT J:Y = Y + 1: NEXT K: NEXT I
  3. 30 DIM B(7,7),C(7,7),DX(7),DY(7),S(64,8),Z(64,7):SP = 0:S$ = ""
  4. 40 FOR I = 0 TO 7: READ DX(I),DY(I): NEXT I
  5. 50 FOR Y = 0 TO 7: FOR X = 0 TO 7: READ C(X,Y): NEXT X: NEXT Y
  6. 70 N = 1:X = 0:Y = 0: GOTO 1000
  7. 80 PRINT S$;: PRINT TAB( 41);: INVERSE : PRINT "PRESS ENTER";: NORMAL : INPUT A$
  8. 90 TEXT : HOME : END
  9. 1000 S$ = S$ + CHR$ (65 + X) + CHR$ (56 - Y):B(X,Y) = N: COLOR = 1: VLIN 4 * Y + 1,4 * Y + 2 AT 3 * X + 1: IF N = 64 THEN 80
  10. 1010 S$ = S$ + " ":N = N + 1:D = - 1: GOSUB 2000: FOR I = 0 TO 7:X1 = X + DX(I):Y1 = Y + DY(I): IF X1 > - 1 THEN IF X1 < 8 THEN IF Y1 > - 1 THEN IF Y1 < 8 THEN S(SP,I) = C(X1,Y1): GOTO 1012
  11. 1011 S(SP,I) = 9999
  12. 1012 Z(SP,I) = I: NEXT I
  13. 1015 FOR I = 6 TO 0 STEP - 1: FOR J = 0 TO I: IF S(SP,J) > S(SP,J + 1) THEN TEMP = S(SP,J):S(SP,J) = S(SP,J + 1):S(SP,J + 1) = TEMP:TEMP = Z(SP,J):Z(SP,J) = Z(SP,J + 1):Z(SP,J + 1) = TEMP
  14. 1016 NEXT J: NEXT I:S(SP,8) = 0
  15. 1020 IF S(SP,S(SP,8)) > 8 THEN 1040
  16. 1021 X = X + DX(Z(SP,S(SP,8))):Y = Y + DY(Z(SP,S(SP,8))): IF B(X,Y) = 0 THEN SP = SP + 1: GOTO 1000
  17. 1030 X = X - DX(Z(SP,S(SP,8))):Y = Y - DY(Z(SP,S(SP,8))):S(SP,8) = S(SP,8) + 1: IF S(SP,8) < 8 THEN 1020
  18. 1040 S$ = LEFT$ (S$, LEN (S$) - 4):B(X,Y) = 0:SUM = X + Y:MOD = SUM - 2 * INT (SUM / 2): COLOR= 7 - 5 * MOD: VLIN 4 * Y + 1,4 * Y + 2 AT 3 * X + 1:D = 1: GOSUB 2000:N = N - 1:SP = SP - 1: IF SP = 0 THEN 80
  19. 1050 GOTO 1030
  20. 2000 FOR I = 0 TO 7:X1 = X + DX(I):Y1 = Y + DY(I): IF X1 > - 1 THEN IF X1 < 8 THEN IF Y1 > - 1 THEN IF Y1 < 8 THEN C(X1,Y1) = C(X1,Y1) + D
  21. 2010 NEXT I: RETURN
  22. 3000 DATA 1,-2,2,-1,2,1,1,2,-1,2,-2,1,-2,-1,-1,-2
  23. 4000 DATA 2,3,4,4,4,4,3,2
  24. 4010 DATA 3,4,6,6,6,6,4,3
  25. 4020 DATA 4,6,8,8,8,8,6,4
  26. 4030 DATA 4,6,8,8,8,8,6,4
  27. 4040 DATA 4,6,8,8,8,8,6,4
  28. 4050 DATA 4,6,8,8,8,8,6,4
  29. 4060 DATA 3,4,6,6,6,6,4,3
  30. 4070 DATA 2,3,4,4,4,4,3,2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement