moved three-sigs logic into physics

This commit is contained in:
Richard Harrington 2013-09-01 22:31:16 -04:00
parent dd1bf0e1e0
commit 078f927c29
2 changed files with 17 additions and 9 deletions

View File

@ -1,5 +1,6 @@
(ns robotwar.browser
(:use [robotwar.constants]))
(:use [robotwar.constants])
(:require [robotwar.physics :as physics]))
(defn worlds-for-browser
"builds a sequence of worlds with the robots' brains
@ -7,20 +8,22 @@
Fast-forward factor will be dynamically added by animation
function in browser."
[worlds]
(letfn [(necessary-fields [robot]
(select-keys robot [:pos-x
(letfn [(select-robot-keys [robot]
(select-keys robot [:idx
: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))))
(three-sigs-map [m]
(zipmap (keys m)
(map #(if (float? %)
(physics/three-sigs %)
%)
(vals m))))
(compact-robots [world]
(update-in
world
[:robots]
#(mapv (comp three-sigs necessary-fields) %)))]
#(mapv (comp three-sigs-map select-robot-keys) %)))]
(map compact-robots worlds)))

View File

@ -1,5 +1,10 @@
(ns robotwar.physics)
; precision functions
(defn three-sigs [x]
(double (/ (Math/round (* x 1000)) 1000)))
; trig functions
(defn robotwar-deg->clojure-deg