瀏覽代碼

Factor out with-action helper function

Thomas Dy 9 年之前
父節點
當前提交
dd4c1352f4
共有 1 個文件被更改,包括 4 次插入1 次删除
  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)