Skip to content

Instantly share code, notes, and snippets.

@krisajenkins
Created August 12, 2013 20:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisajenkins/6214585 to your computer and use it in GitHub Desktop.
Save krisajenkins/6214585 to your computer and use it in GitHub Desktop.
LDN Clojure Bot
(defn possible-new-positions
[[x y]]
(map (fn [[x' y']]
[(+ x x')
(+ y y')]) (vec tron/legal-moves)))
(defn safe-move?
[look position]
(nil?
(look position)))
(defn available-safe-moves
[look pos]
(filter (partial safe-move? look) (possible-new-positions pos)))
(defn random-mover
"To infinity and beyond!"
[look {pos :pos}]
{:pos (rand-nth (available-safe-moves look pos))}
)
(defn habitual-random-mover
"To infinity and beyond!"
[look {pos :pos
previous :previous
:as state}]
(let [direction (map - pos (or previous [0 0]))
next-pos (map + direction pos)]
(if (safe-move? look next-pos)
{:pos next-pos
:previous pos}
(merge (random-mover look state)
{:previous pos}))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment