language: CLIPS (clips 6.24)
date: 128 days 1 hour ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(deftemplate hunter "A hunter"
  (slot agent (default Xena))
  (slot x (type INTEGER))
  (slot y (type INTEGER))
  (slot alive (default TRUE)))
 
(deftemplate cave
  "Cave objects sore the hunter's model of the world"
  (slot x (type INTEGER))               ; (x,y) coordinates of cave
  (slot y (type INTEGER))               ; 
  (slot visited (default FALSE))        ; Has the hunter been in it?
  (slot stench (default UNKNOWN))       ; Does the cave smell?
  (slot breeze (default UNKNOWN))       ; Is it breezy?
  (slot glitter (default UNKNOWN))      ; Is there a glitter in it?
  (slot has-wumpus (default UNKNOWN))   ; Is there a wumpus here?
  (slot has-pit (default UNKNOWN))      ; Is there a pit here?
  (slot has-gold (default UNKNOWN))     ; Is their gold here?
  (slot has-exit (default UNKNOWN))
  (slot safe (default UNKNOWN)))        ; Is the cave safe -- no wumpus, no pit?
 
;; functions -----------------------------------------------------------------
 
(deffunction buildworld (?width ?height)
  ;; (buildworld N M) makes cave assertions for a NxM rectangular  world.
  (printout t "Adding adj asserts for a " ?width " by " ?height "  world." crlf)
  (bind ?x 1)
  (while (<= ?x ?width)
    (bind ?y 1)
    (while (<= ?y ?height)
      (if (> ?x 1) then (assert (adj  ?x ?y (- ?x 1) ?y)))
      (if (> ?y 1) then (assert (adj ?x ?y ?x (- ?y 1))))
      (if (< ?x ?width) then (assert (adj ?x ?y (+ ?x 1) ?y)))
      (if (< ?y ?height) then (assert (adj ?x ?y ?x (+ ?y 1))))
      (bind ?y (+ 1 ?y)))
    (bind ?x (+ ?x 1))))