Created
August 15, 2012 17:52
-
-
Save ckirkendall/3361937 to your computer and use it in GitHub Desktop.
optimization of create-rep
This file contains hidden or 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 move [direction {:keys x y :as piece}] | |
(case direction | |
:down (assoc piece :y (inc y)) | |
:right (assoc piece :x (inc x)) | |
:left (assoc piece :x (dec x)) | |
:up (assoc piece :y (dec y)) | |
piece)) | |
(defn handle-input [k game-state] | |
(let [filt-func #(= "player" (:entity-name %)) | |
[start [player] end] (partition-by filt-func game-state)] | |
(if player | |
(concat start end [(move k player)]) | |
game-state)) | |
(defn create-rep [game-state] | |
(let [xy-map (reduce #(assoc %1 [(:x %2) (:y %2)] (:display %2)) {} game-state) | |
board (for [y (range 0 24) | |
x (range 0 80)] | |
(let [sqr (get [x y] xy-map)] | |
(if sqr sqr " ")))] | |
(doseq [line (partition 80 board)] | |
(apply str line)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment