Created
August 27, 2013 08:22
-
-
Save ikitommi/6351028 to your computer and use it in GitHub Desktop.
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
(ns tron.kekkonen) | |
(defn addv [a b] (mapv + a b)) | |
(defn turn-left [[dx dy]] [dy (- dx)]) | |
(defn turn-right [[dx dy]] [(- dy) dx]) | |
(defn left? [old-dir new-dir] (= (turn-right new-dir) old-dir)) | |
(defn president | |
[turn & [primary-goal :as original-goals]] | |
(fn [look {:keys [pos dir goals] :or {dir (or primary-goal [0 1]) | |
goals original-goals}}] | |
(letfn | |
[(ok? [new-dir & [dont-turn]] | |
(let [new-pos (addv pos new-dir)] | |
(when-not (look new-pos) | |
{:pos new-pos :dir new-dir :goals (map (if dont-turn identity turn) goals)})))] | |
(or | |
(some ok? goals) | |
(ok? dir true) | |
(ok? (turn-left dir)) | |
(ok? (turn-right dir)))))) | |
(def mannerheim (president identity [0 -1])) | |
(def kekkonen (president turn-left [0 -1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment