mirror of
https://github.com/richardharrington/robotwar.git
synced 2024-05-28 23:41:31 +00:00
reduced info per robot being sent to browser (fewer fields, fewer sig-figs per field)
This commit is contained in:
parent
b8567a487b
commit
ef5666d8d2
|
@ -5,13 +5,22 @@
|
|||
"builds a sequence of worlds with the robots' brains
|
||||
removed, for more compact transmission by json.
|
||||
Fast-forward factor will be dynamically added by animation
|
||||
function in browser.
|
||||
TODO: remove some unnecessary robot fields if we need to
|
||||
for speed (we're going to keep them in now for diagnostic
|
||||
purposes in the browser)"
|
||||
function in browser."
|
||||
[worlds]
|
||||
(map (fn [world]
|
||||
(assoc world :robots (mapv #(dissoc % :brain) (:robots world))))
|
||||
worlds))
|
||||
|
||||
|
||||
(letfn [(necessary-fields [robot]
|
||||
(select-keys robot [:pos-x
|
||||
:pos-y
|
||||
:aim
|
||||
:damage
|
||||
:shot-timer]))
|
||||
(three-sigs [robot]
|
||||
(zipmap (keys robot)
|
||||
(map (fn [x]
|
||||
(double (/ (Math/round (* x 1000)) 1000)))
|
||||
(vals robot))))
|
||||
(compact-robots [world]
|
||||
(update-in
|
||||
world
|
||||
[:robots]
|
||||
#(mapv (comp three-sigs necessary-fields) %)))]
|
||||
(map compact-robots worlds)))
|
||||
|
|
Loading…
Reference in New Issue
Block a user