mirror of
https://github.com/richardharrington/robotwar.git
synced 2024-05-28 08:41:28 +00:00
moved three-sigs logic into physics
This commit is contained in:
parent
dd1bf0e1e0
commit
078f927c29
|
@ -1,5 +1,6 @@
|
||||||
(ns robotwar.browser
|
(ns robotwar.browser
|
||||||
(:use [robotwar.constants]))
|
(:use [robotwar.constants])
|
||||||
|
(:require [robotwar.physics :as physics]))
|
||||||
|
|
||||||
(defn worlds-for-browser
|
(defn worlds-for-browser
|
||||||
"builds a sequence of worlds with the robots' brains
|
"builds a sequence of worlds with the robots' brains
|
||||||
|
@ -7,20 +8,22 @@
|
||||||
Fast-forward factor will be dynamically added by animation
|
Fast-forward factor will be dynamically added by animation
|
||||||
function in browser."
|
function in browser."
|
||||||
[worlds]
|
[worlds]
|
||||||
(letfn [(necessary-fields [robot]
|
(letfn [(select-robot-keys [robot]
|
||||||
(select-keys robot [:pos-x
|
(select-keys robot [:idx
|
||||||
|
:pos-x
|
||||||
:pos-y
|
:pos-y
|
||||||
:aim
|
:aim
|
||||||
:damage
|
:damage
|
||||||
:shot-timer]))
|
:shot-timer]))
|
||||||
(three-sigs [robot]
|
(three-sigs-map [m]
|
||||||
(zipmap (keys robot)
|
(zipmap (keys m)
|
||||||
(map (fn [x]
|
(map #(if (float? %)
|
||||||
(double (/ (Math/round (* x 1000)) 1000)))
|
(physics/three-sigs %)
|
||||||
(vals robot))))
|
%)
|
||||||
|
(vals m))))
|
||||||
(compact-robots [world]
|
(compact-robots [world]
|
||||||
(update-in
|
(update-in
|
||||||
world
|
world
|
||||||
[:robots]
|
[:robots]
|
||||||
#(mapv (comp three-sigs necessary-fields) %)))]
|
#(mapv (comp three-sigs-map select-robot-keys) %)))]
|
||||||
(map compact-robots worlds)))
|
(map compact-robots worlds)))
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
(ns robotwar.physics)
|
(ns robotwar.physics)
|
||||||
|
|
||||||
|
; precision functions
|
||||||
|
|
||||||
|
(defn three-sigs [x]
|
||||||
|
(double (/ (Math/round (* x 1000)) 1000)))
|
||||||
|
|
||||||
; trig functions
|
; trig functions
|
||||||
|
|
||||||
(defn robotwar-deg->clojure-deg
|
(defn robotwar-deg->clojure-deg
|
||||||
|
|
Loading…
Reference in New Issue
Block a user