Jump to content
  • Advertisement
Sign in to follow this  
_mito_

What wrong with my lisp AI code???

This topic is 4834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have to work on "vacuum world" with lisp.I write the code to move my agent in the vacuum world.My code appear below. (defstructure (state-vacuum-agent ; name of this agent (:include agent ; specializes the AGENT class (program (let ((location '(1 1)) ; state variables with their initial values (heading 'east) (row 0) (col 0) (numofcleaned 0) (know 'No) (crow 1) (ccol 1) (bumpc 0)) #'(lambda (percept) (if (eql know 'No) (progn (destructuring-bind (bump dirt home) percept (cond (dirt (progn (setq numofcleaned (+ numofcleaned 1)) 'suck ) ) (home (progn (setq ccol (+ ccol 1)) 'forward ) ) (bump (progn (setq bumpc (+ bumpc 1)) (if (= bumpc 1) (progn (setq ccol (- ccol 1)) (setq col ccol) (setq heading 'north) '(turn left) ) (if (= bumpc 2) (progn (setq crow (- crow 1)) (setq row crow) (setq heading 'west) (setq know 'Yes) '(turn left) ) ) ) ) ) (t (progn (if (eql heading 'east) (setq ccol (+ ccol 1)) (if (eql heading 'west) (setq ccol (- ccol 1)) (if (eql heading 'north) (setq crow (+ crow 1)) (if (eql heading 'south) (setq crow (- crow 1)))))) 'forward ) ) ) ) ) ) )))))) The purpose of my code is to detect width and height of the world the my agent live in. I decide to move my agent from the Home pos(1,1) on the buttom-left corner of the world along the horizontal line to the pos(w,1) when it's bumped with the wall I decide to make my agent to turn left and move along the vertical line to the pos(w,h) at the top-right until it's bumped. So that algorithm I mention above should detect the width and height of the world ,but it's not. when I simulation it appear that my agent perform bad move. (w mean width of the world and h indicated height of the world) I don't know how to improve my code because I think it's right.Every one who good at Lisp and AI Help me please. Thank you very much. Best regard Jitkasem

Share this post


Link to post
Share on other sites
Advertisement
You should probably surround that with the [code] and [/code] tags, Lisp can be pretty hard to read when it doesn't have leading whitespace.

Share this post


Link to post
Share on other sites
Okey, thank you my code look like this.


(defstructure (state-vacuum-agent ; name of this agent
(:include agent ; specializes the AGENT class
(program
(let ((location '(1 1)) ; state variables with their initial values
(heading 'east)
(row 0)
(col 0)
(numofcleaned 0)
(know 'No)
(crow 1)
(ccol 1)
(bumpc 0))
#'(lambda (percept)
(if (eql know 'No)
(progn
(destructuring-bind (bump dirt home) percept
(cond (dirt
(progn
(setq numofcleaned (+ numofcleaned 1))
'suck
)
)
(home
(progn
(setq ccol (+ ccol 1))
'forward
)
)
(bump
(progn
(setq bumpc (+ bumpc 1))
(if (= bumpc 1)
(progn
(setq ccol (- ccol 1))
(setq col ccol)
(setq heading 'north)
'(turn left)
)
(if (= bumpc 2)
(progn
(setq crow (- crow 1))
(setq row crow)
(setq heading 'west)
(setq know 'Yes)
'(turn left)
)
)
)
)
)
(t
(progn
(if (eql heading 'east)
(setq ccol (+ ccol 1))
(if (eql heading 'west)
(setq ccol (- ccol 1))
(if (eql heading 'north)
(setq crow (+ crow 1))
(if (eql heading 'south)
(setq crow (- crow 1))))))
'forward
)
)
)
)
)
)


))))))

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!