Advertisement
zbeucler

grid-chase.ss

Mar 11th, 2021
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. (define randomize
  2. (lambda (lst)
  3. (let ((size (length lst)))
  4. (cond
  5. ((< size 2) lst)
  6. (else
  7. (let ((node-num (random size)))
  8. (cons (list-ref lst node-num)
  9. (randomize (removex node-num lst)))))))))
  10.  
  11. (define removex
  12. (lambda (num lst)
  13. (if (= num 0)
  14. (cdr lst)
  15. ;else
  16. (cons (car lst) (removex (- num 1) (cdr lst))))))
  17.  
  18. (define get-next-goal0
  19. (lambda (point)
  20. (if (< (+ (abs (- (car robot) (car point)))
  21. (abs (- (cadr robot) (cadr point)))) 2)
  22. point
  23. ;else
  24. (get-next-goal point))))
  25.  
  26. (define search
  27. (lambda (grid stop-count)
  28. (search2 grid 1 stop-count)))
  29.  
  30. (define search2
  31. (lambda (grid count stop-count)
  32. (display count)
  33. (newline)
  34. (cond
  35. ((equal? robot goal)
  36. (display "Robot attains the goal"))
  37. ((>= count stop-count)
  38. (display "Took too long")
  39. (newline))
  40. (else
  41. (pause pause-num)
  42. (search-robot grid)
  43. (if (null? robot)
  44. (display "Cannot reach the goal")
  45. (begin
  46. (pause pause-num)
  47. (search-goal grid)
  48. (search2 grid (+ count 1) stop-count)))))))
  49.  
  50. (define search-robot
  51. (lambda (grid)
  52. (let ((next-robot (get-next-robot robot)))
  53. (set! robot next-robot)
  54. (if (not (null? robot))
  55. (draw-moved-robotx robot)))))
  56.  
  57. (define search-goal
  58. (lambda (grid)
  59. (let ((next-goal (get-next-goal0 goal)))
  60. (set! goal next-goal)
  61. (draw-moved-goalx goal))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement