Advertisement
Latkoski

движење духови

Jan 11th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. (defun depth-first-search (start goal been-list moves)
  2. (cond ((equal (nth 0 start) goal)
  3. (reverse (cons start been-list)))
  4. (t (try-moves start goal been-list moves moves))))
  5.  
  6. ; Try-moves scans down the list of moves in moves-to-try,
  7. ; attempting to generate a child state. If it produces
  8. ; this state, it calls depth-first-search to complete the search.
  9.  
  10. (defun try-moves (start goal been-list moves-to-try moves)
  11. (cond ((null moves-to-try) nil)
  12. ((member start been-list :test #'equal) nil)
  13. (t (let ((child (funcall (car moves-to-try) start)))
  14. (if child
  15. (or (depth-first-search (funcall (car moves-to-try) start)
  16. goal
  17. (cons start been-list)
  18. moves)
  19. (try-moves start goal been-list (cdr moves-to-try) moves))
  20. (try-moves start goal been-list (cdr moves-to-try) moves))))))
  21.  
  22. ; run-depth-first calls depth-first-search, initializing the been-list to ().
  23. (defun run-depth (start goal moves)
  24. (depth-first-search start goal () moves))
  25.  
  26. ; dodajte ja listata na potezi koi treba da se probaat za sekoja sostojba i odkomentirajte ja slednata linija
  27. ;(run-depth '(1 1) '(3 3) '(moves))
  28.  
  29. (defun depth-first-search (start goal been-list moves)
  30. (cond ((equal (nth 0 start) goal)
  31. (reverse (cons start been-list)))
  32. (t (try-moves start goal been-list moves moves))))
  33.  
  34. ; Try-moves scans down the list of moves in moves-to-try,
  35. ; attempting to generate a child state. If it produces
  36. ; this state, it calls depth-first-search to complete the search.
  37.  
  38. (defun try-moves (start goal been-list moves-to-try moves)
  39. (cond ((null moves-to-try) nil)
  40. ((member start been-list :test #'equal) nil)
  41. (t (let ((child (funcall (car moves-to-try) start)))
  42. (if child
  43. (or (depth-first-search (funcall (car moves-to-try) start)
  44. goal
  45. (cons start been-list)
  46. moves)
  47. (try-moves start goal been-list (cdr moves-to-try) moves))
  48. (try-moves start goal been-list (cdr moves-to-try) moves))))))
  49.  
  50. ; run-depth-first calls depth-first-search, initializing the been-list to ().
  51. (defun run-depth (start goal moves)
  52. (depth-first-search start goal () moves))
  53.  
  54.  
  55.  
  56. (defvar lista '(((1 1)(2 2 0))(2 1)))
  57.  
  58.  
  59. (setq player (caar lista))
  60. (setq duh (cadar lista))
  61. (setq cel (cadr lista))
  62.  
  63.  
  64. (defun makestate (x y)
  65. (list x y)
  66. )
  67.  
  68. (defun safe (state)
  69. (cond
  70. ((and (> (car player) 0)(> (cadr player) 0) (< (car player) 4) (< (cadr player) 4)
  71. (not (equal (car player) (car duh)))(not (equal (cadr player) (cadr duh)))) state)
  72. (t nil)
  73. )
  74. )
  75.  
  76.  
  77. (defun smeni (duh)
  78. (cond
  79. ((eq (car duh) 3) 1)
  80. ((eq (car duh) 1) 0)
  81. (t (caddr duh))
  82. )
  83. )
  84.  
  85.  
  86. (defun gore(state)
  87. (cond
  88. ((eq (smeni duh) 0) (safe (makestate (list (caar state) (+ (cadar state)1)) (list (+ (caadr state) 1) (cadadr duh) 0))))
  89. ((eq (smeni duh) 1) (safe (makestate (list (caar state) (+ (cadar state)1)) (list (- (caadr state) 1) (cadadr duh) 1))))
  90. )
  91. )
  92.  
  93. (defun dolu(player duh)
  94. (cond
  95. ((eq (smeni duh) 0) (safe (makestate (list (car state) (- (cadr state)1)) (list (+ (caadr state) 1) (cadadr state) 0))))
  96. ((eq (smeni duh) 1) (safe (makestate (list (car state) (- (cadr state)1)) (list (- (caadr state) 1) (cadadr state) 1))))
  97. )
  98. )
  99.  
  100. (defun levo(player duh)
  101. (cond
  102. ((eq (smeni duh) 0) (safe (makestate (list (- (car player) 1) (cadr state)) (list (+ (caadr state) 1) (cadadr state) 0))))
  103. ((eq (smeni duh) 1) (safe (makestate (list (- (car player) 1) (cadr state)) (list (- (caadr state) 1) (cadadr state) 1))))
  104. )
  105. )
  106.  
  107. (defun desno(player duh)
  108. (cond
  109. ((eq (smeni duh) 0) (safe (makestate (list (+ (car player) 1) (cadr player)) (list (+ (caadr state) 1) (cadadr state) 0))))
  110. ((eq (smeni duh) 1) (safe (makestate (list (+ (car player) 1) (cadr player)) (list (- (caadr state) 1) (cadadr state) 1))))
  111. )
  112. )
  113.  
  114. (setq moves '(gore dolu levo desno))
  115. (depth-first-search '((1 1) (2 2 0)) '(2 1) '() moves)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement