Created
August 12, 2013 20:03
-
-
Save krisajenkins/6214585 to your computer and use it in GitHub Desktop.
LDN Clojure Bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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