Skip to content

Instantly share code, notes, and snippets.

@tuturto
Last active August 29, 2015 14:02
Show Gist options
  • Save tuturto/71d02d4561864d90f526 to your computer and use it in GitHub Desktop.
Save tuturto/71d02d4561864d90f526 to your computer and use it in GitHub Desktop.
wallᵒ or not to wallᵒ
(setv level-data
[[:wall-data
[(, (, 5 5) :rock-wall)
(, (, 6 5) :rock-wall)
(, (, 7 5) :tile-wall)]]
[:floor-data
[(, (, 5 6) :dirt-floor)
(, (, 6 6) :rock-floor)
(, (, 7 6) :rock-floor)]]])
(defn wall-dataᵒ [level wall-data]
(fresh [x]
(≡ x [:wall-data wall-data])
(memberᵒ x level)))
(defn floor-dataᵒ [level floor-data]
(fresh [x]
(≡ x [:floor-data floor-data])
(memberᵒ x level)))
(defn wallᵒ [level location id]
(fresh [data tile]
(wall-dataᵒ level data)
(≡ tile (, location id))
(memberᵒ tile data)))
(defn floorᵒ [level location id]
(fresh [data tile]
(floor-dataᵒ level data)
(≡ tile (, location id))
(memberᵒ tile data)))
=> (run* [q]
(wallᵒ level-data (, 6 5) q)) ;; what kind of wall is at location (6 5)?
[:rock-wall]
=> (run* [q]
(fresh [location id]
(floorᵒ level-data location id)
(≡ (, location id) q))) ;; what kind of floor the level has?
[((5, 6), :dirt-floor), ((6, 6), :rock-floor), ((7, 6), :rock-floor)]
=> (run* [q]
(floorᵒ level-data q :rock-floor)) ;; where is there rock-floor?
[(6, 6), (7, 6)]
=> (run 1 [q]
(wallᵒ q (, 1 1) :rock-wall)
(floorᵒ q (, 1 2) :dirt-floor)
(floorᵒ q (, 1 3) :dirt-floor)) ;; if I have rock-wall at (1 1) and dirt-floor at (1 2) and (1 3), what kind of level do I have?
[([:wall-data ([[1 1] :rock-wall] . <'_.0'>)] [:floor-data ([[1 2] :dirt-floor] [[1 3] :dirt-floor] . <'_.1'>)] . <'_.2'>)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment