Browse Source

Factor out with-action helper function

Thomas Dy 8 years ago
parent
commit
dd4c1352f4
1 changed files with 4 additions and 1 deletions
  1. 4 1
      src/bombnet/game.clj

+ 4 - 1
src/bombnet/game.clj

@@ -44,6 +44,9 @@
    :players []
    :bombs []})
 
+(defn with-action [typ]
+  (fn [p] (= typ (get-in p [:action :type]))))
+
 (defn check-positions [state]
   "Returns a vector of valid new player positions"
   (let [{:keys [board players bombs]} state
@@ -66,7 +69,7 @@
 (defn perform-movement [initial-state]
   (loop [state initial-state]
     (let [{players :players} state
-          wants-to-move (fn [p] (= "move" (get-in p [:action :type])))
+          wants-to-move (with-action "move")
           to-move (vec (map (fn [p]
                               (let [p2 (assoc p :prev-pos (get p :pos))]
                                 (if (wants-to-move p2)