Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun depth-first-search (start goal been-list moves)
- (cond ((equal (nth 0 start) goal)
- (reverse (cons start been-list)))
- (t (try-moves start goal been-list moves moves))))
- ; Try-moves scans down the list of moves in moves-to-try,
- ; attempting to generate a child state. If it produces
- ; this state, it calls depth-first-search to complete the search.
- (defun try-moves (start goal been-list moves-to-try moves)
- (cond ((null moves-to-try) nil)
- ((member start been-list :test #'equal) nil)
- (t (let ((child (funcall (car moves-to-try) start)))
- (if child
- (or (depth-first-search (funcall (car moves-to-try) start)
- goal
- (cons start been-list)
- moves)
- (try-moves start goal been-list (cdr moves-to-try) moves))
- (try-moves start goal been-list (cdr moves-to-try) moves))))))
- ; run-depth-first calls depth-first-search, initializing the been-list to ().
- (defun run-depth (start goal moves)
- (depth-first-search start goal () moves))
- ; dodajte ja listata na potezi koi treba da se probaat za sekoja sostojba i odkomentirajte ja slednata linija
- ;(run-depth '(1 1) '(3 3) '(moves))
- (defun depth-first-search (start goal been-list moves)
- (cond ((equal (nth 0 start) goal)
- (reverse (cons start been-list)))
- (t (try-moves start goal been-list moves moves))))
- ; Try-moves scans down the list of moves in moves-to-try,
- ; attempting to generate a child state. If it produces
- ; this state, it calls depth-first-search to complete the search.
- (defun try-moves (start goal been-list moves-to-try moves)
- (cond ((null moves-to-try) nil)
- ((member start been-list :test #'equal) nil)
- (t (let ((child (funcall (car moves-to-try) start)))
- (if child
- (or (depth-first-search (funcall (car moves-to-try) start)
- goal
- (cons start been-list)
- moves)
- (try-moves start goal been-list (cdr moves-to-try) moves))
- (try-moves start goal been-list (cdr moves-to-try) moves))))))
- ; run-depth-first calls depth-first-search, initializing the been-list to ().
- (defun run-depth (start goal moves)
- (depth-first-search start goal () moves))
- (defvar lista '(((1 1)(2 2 0))(2 1)))
- (setq player (caar lista))
- (setq duh (cadar lista))
- (setq cel (cadr lista))
- (defun makestate (x y)
- (list x y)
- )
- (defun safe (state)
- (cond
- ((and (> (car player) 0)(> (cadr player) 0) (< (car player) 4) (< (cadr player) 4)
- (not (equal (car player) (car duh)))(not (equal (cadr player) (cadr duh)))) state)
- (t nil)
- )
- )
- (defun smeni (duh)
- (cond
- ((eq (car duh) 3) 1)
- ((eq (car duh) 1) 0)
- (t (caddr duh))
- )
- )
- (defun gore(state)
- (cond
- ((eq (smeni duh) 0) (safe (makestate (list (caar state) (+ (cadar state)1)) (list (+ (caadr state) 1) (cadadr duh) 0))))
- ((eq (smeni duh) 1) (safe (makestate (list (caar state) (+ (cadar state)1)) (list (- (caadr state) 1) (cadadr duh) 1))))
- )
- )
- (defun dolu(player duh)
- (cond
- ((eq (smeni duh) 0) (safe (makestate (list (car state) (- (cadr state)1)) (list (+ (caadr state) 1) (cadadr state) 0))))
- ((eq (smeni duh) 1) (safe (makestate (list (car state) (- (cadr state)1)) (list (- (caadr state) 1) (cadadr state) 1))))
- )
- )
- (defun levo(player duh)
- (cond
- ((eq (smeni duh) 0) (safe (makestate (list (- (car player) 1) (cadr state)) (list (+ (caadr state) 1) (cadadr state) 0))))
- ((eq (smeni duh) 1) (safe (makestate (list (- (car player) 1) (cadr state)) (list (- (caadr state) 1) (cadadr state) 1))))
- )
- )
- (defun desno(player duh)
- (cond
- ((eq (smeni duh) 0) (safe (makestate (list (+ (car player) 1) (cadr player)) (list (+ (caadr state) 1) (cadadr state) 0))))
- ((eq (smeni duh) 1) (safe (makestate (list (+ (car player) 1) (cadr player)) (list (- (caadr state) 1) (cadadr state) 1))))
- )
- )
- (setq moves '(gore dolu levo desno))
- (depth-first-search '((1 1) (2 2 0)) '(2 1) '() moves)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement