changed all values & calculations outside the brain to floating point

(also added stuff to the register functions that pull and push
from the brain to the robot fields, casting to integer when
pulling, and float when pushing)
This commit is contained in:
Richard Harrington 2013-08-11 23:10:23 -04:00
parent 32eac97e0c
commit 50ddd8d2b7
6 changed files with 25 additions and 22 deletions

View File

@ -7,7 +7,7 @@
; this is a hacky place for messing with stuff.
(def world
(world/init-world 256 256 [test-programs/multi-use-program]))
(world/init-world 256.0 256.0 [test-programs/multi-use-program]))
(def worlds (world/iterate-worlds world))
(def robots (:robots world))

View File

@ -35,19 +35,22 @@
data))})
(def robot-field-read-mixin
; returns the value of a field in the robot hash-map
{:read-register (fn [this world]
(get-in
world
(conj (path-to-robot (:robot-idx this)) (:field-name this))))})
; returns the value of a field in the robot hash-map,
; rounded to an integer
{:read-register
(fn [this world]
(Math/round (get-in
world
(conj (path-to-robot (:robot-idx this)) (:field-name this)))))})
(def robot-field-write-mixin
; returns a world with the value of a field in the robot hash map altered
; (with the number being cast to floating point before being pushed)
{:write-register (fn [this world data]
(assoc-in
world
(conj (path-to-robot (:robot-idx this)) (:field-name this))
data))})
(float data)))})
(def no-op-write-mixin
; returns a world with nothing changed

View File

@ -4,7 +4,7 @@
; MAX_ACCEL is in decimeters per second per second.
; TODO: should be passed in from some higher level module, or a config module.
(def MAX_ACCEL 40)
(def MAX_ACCEL 40.0)
; yay classical mechanics
@ -17,7 +17,7 @@
(defn d-with-constant-a
[d vi a t]
(double (+ d (* vi t) (/ (* a (Math/pow t 2)) 2))))
(+ d (* vi t) (/ (* a (Math/pow t 2)) 2.0)))
(defn v-with-constant-a
[vi a t]
@ -36,7 +36,7 @@
(if (> t' t)
{:d (d-with-constant-a d vi a t)
:v (v-with-constant-a vi a t)}
{:d (d-with-constant-a (d-with-constant-a d vi a t') vf 0 (- t t'))
{:d (d-with-constant-a (d-with-constant-a d vi a t') vf 0.0 (- t t'))
:v vf})))
; TODO: velocity-given-desired-velocity-and-distance or something
@ -58,10 +58,10 @@
{:idx idx
:pos-x (:pos-x attributes)
:pos-y (:pos-y attributes)
:v-x 0
:v-y 0
:desired-v-x 0
:desired-v-y 0
:v-x 0.0
:v-y 0.0
:desired-v-x 0.0
:desired-v-y 0.0
:aim (:aim attributes)
:damage (:damage attributes)
:brain (brain/init-brain src-code (register/init-registers idx))})

View File

@ -3,7 +3,7 @@
(:require [robotwar.robot :as robot]))
(def TICK_DURATION 1)
(def TICK_DURATION 1.0)
; TODO: pass in tick-duration to world from somewhere else.
@ -20,8 +20,8 @@
program
{:pos-x (rand-int width)
:pos-y (rand-int height)
:aim 0
:damage 0}))
:aim 0.0
:damage 0.0}))
programs))
:robot-idx 0})

View File

@ -7,7 +7,7 @@
[robotwar.test-programs :as test-programs]))
(def initial-world
(world/init-world 256 256 [test-programs/multi-use-program]))
(world/init-world 256.0 256.0 [test-programs/multi-use-program]))
(def worlds (iterate world/tick-world initial-world))

View File

@ -4,7 +4,7 @@
[robotwar.register])
(:require [robotwar.world :as world]))
(def world (world/init-world 256 256 [""]))
(def world (world/init-world 256.0 256.0 [""]))
(def robot-path [:robots 0])
(def reg-path [:robots 0 :brain :registers])
(def registers (get-in world reg-path))
@ -48,7 +48,7 @@
(deftest read-only-test
(testing "can read from read-only registers, but not write to them
(and also the robot fields don't get written to)"
(let [world1 (assoc-in world [:robots 0 :damage] 50)
(let [world1 (assoc-in world [:robots 0 :damage] 50.0)
registers1 (get-registers world1)
world2 (write-register (registers "DAMAGE") world1 25)
registers2 (get-registers world2)]
@ -57,7 +57,7 @@
(is (= (read-register (registers2 "DAMAGE") world2)
50))
(is (= (get-in world2 [:robots 0 :damage])
50)))))
50.0)))))
(deftest read-write-test
(testing "can read and write from registers that are interfaces
@ -67,4 +67,4 @@
(is (= (read-register (new-registers "SPEEDX") new-world)
90))
(is (= (get-in new-world [:robots 0 :desired-v-x])
90)))))
90.0)))))