diff --git a/src/robotwar/register.clj b/src/robotwar/register.clj index 14a3eaf..0755fdd 100644 --- a/src/robotwar/register.clj +++ b/src/robotwar/register.clj @@ -123,7 +123,8 @@ GAME-SECONDS-PER-SHOT)] (assoc world-with-new-shot-timer - :shells (merge shells (shell/init-shell pos-x pos-y aim next-shell-id data)) + :shells (merge shells {next-shell-id + (shell/init-shell pos-x pos-y aim data)}) :next-shell-id (inc next-shell-id))))))}) (defn get-target-register diff --git a/src/robotwar/shell.clj b/src/robotwar/shell.clj index cb5e0d4..d7e3e56 100644 --- a/src/robotwar/shell.clj +++ b/src/robotwar/shell.clj @@ -3,12 +3,11 @@ (:require [robotwar.physics :as physics])) (defn init-shell - [pos-x pos-y aim id distance] + [pos-x pos-y aim distance] ; TODO: make the starting point dependent upon the robot radius, ; which should be in constants. (let [{unit-x :x unit-y :y} (physics/decompose-angle aim)] - {:id id - :pos-x pos-x + {:pos-x pos-x :pos-y pos-y :v-x (* unit-x SHELL-SPEED) :v-y (* unit-y SHELL-SPEED) diff --git a/src/robotwar/world.clj b/src/robotwar/world.clj index f57ed92..06afd05 100644 --- a/src/robotwar/world.clj +++ b/src/robotwar/world.clj @@ -29,9 +29,17 @@ (robot/tick-robot (robots robot-idx) world)) starting-world (range (count (:robots starting-world)))) - ticked-shells (map shell/tick-shell shells) - live-shells (remove :exploded ticked-shells) - exploded-shells (filter :exploded ticked-shells)] + ticked-shells (zipmap (keys shells) + (map shell/tick-shell (vals shells))) + + ; TODO: Is this the most idiomatic way to map a hash-map, testing + ; each value in the hash-map on a predicate and then returning another hash-map? + ; looks clunky. + + live-shells (into {} (remove #(:exploded (val %)) + ticked-shells)) + exploded-shells (into {} (filter #(:exploded (val %)) + ticked-shells))] ; TODO: make this a real let-binding, that determines ; which robots were damaged. (let [damaged-world ticked-robots-world]