|
@@ -91,6 +91,49 @@
|
|
|
proposed-state
|
|
|
(recur (assoc state :players valid-players))))))
|
|
|
|
|
|
+(def ^:const min-bomb-timer 1)
|
|
|
+(def ^:const max-bomb-timer 5)
|
|
|
+(def ^:const bomb-power 99)
|
|
|
+
|
|
|
+(defn ^:private clamp [a lbound ubound]
|
|
|
+ (max lbound (min ubound a)))
|
|
|
+
|
|
|
+(defn ^:private merge-by-key [k coll1 coll2]
|
|
|
+ (->> (merge
|
|
|
+ (group-by k coll1)
|
|
|
+ (group-by k coll2))
|
|
|
+ vals
|
|
|
+ (apply concat)))
|
|
|
+
|
|
|
+(defn perform-bomb-placement [state]
|
|
|
+ (let [{bombs :bombs players :players} state
|
|
|
+ get-bomb (fn [p]
|
|
|
+ (let [pos (:pos p)
|
|
|
+ power bomb-power
|
|
|
+ params (:action p)
|
|
|
+ timer (clamp
|
|
|
+ (:timer params)
|
|
|
+ min-bomb-timer
|
|
|
+ max-bomb-timer)
|
|
|
+ diagonal? (boolean (:diagonal? params))]
|
|
|
+ {:pos pos :power power :counter timer :diagonal? diagonal?}))
|
|
|
+ bombs-to-place (->> players
|
|
|
+ (filter (with-action "bomb"))
|
|
|
+ (map get-bomb))
|
|
|
+ new-bombs (merge-by-key :pos bombs-to-place bombs)
|
|
|
+ new-players (mapv-if
|
|
|
+ (with-action "bomb")
|
|
|
+ #(dissoc % :action)
|
|
|
+ players)]
|
|
|
+ (-> state
|
|
|
+ (assoc :bombs new-bombs)
|
|
|
+ (assoc :players new-players))))
|
|
|
+
|
|
|
+(let [state {:board (new-board 5 5)
|
|
|
+ :players [{:pos [1 1] :action {:type "bomb" :timer 5}}]
|
|
|
+ :bombs []}]
|
|
|
+ (perform-bomb-placement state))
|
|
|
+
|
|
|
(defn ^:private offset [pos dir] (mapv + pos dir))
|
|
|
|
|
|
(with-test
|