Advertisement
Guest User

Untitled

a guest
Oct 10th, 2010
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.79 KB | None | 0 0
  1. (defn next-directed-cells [ mapref cell destination ]
  2.   "Ranks all valid neighbouring cells according to their distance to the desired direction"
  3.   (let [valid-neighbours (valid-neighbouring-cells mapref cell)
  4.         normalised-direction (first
  5.                               (normalise (substract-points destination cell)))
  6.         translated-to-0 (map (fn [v] (substract-points v cell)) valid-neighbours)
  7.         distances (map
  8.                    (fn [v]
  9.                      (euclidean-distance (first (normalise v))
  10.                                          normalised-direction))
  11.                    translated-to-0)
  12.         zipped-distances (partition 2 (interleave valid-neighbours distances))]
  13.     (map first
  14.          (sort (fn [[_ d1] [_ d2]] (< d1 d2))
  15.                zipped-distances))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement