changed width and height to robot-range-x and robot-range-y and made

them constants

because technically, the robot ranges are the maximum ranges for the
centers of the robots' bodies,
so the actual extent of the arena when
displayed must be slightly larger
This commit is contained in:
Richard Harrington 2013-08-20 12:10:58 -04:00
parent e3b879fba8
commit 9b46900f9b
5 changed files with 19 additions and 17 deletions

View File

@ -4,4 +4,7 @@
(def MAX-ACCEL 4.0) (def MAX-ACCEL 4.0)
(def ^:dynamic *GAME-SECONDS-PER-TICK* 0.03) (def ^:dynamic *GAME-SECONDS-PER-TICK* 0.03)
; ROBOT-RANGE-X and -Y are in meters
(def ROBOT-RANGE-X 256.0)
(def ROBOT-RANGE-Y 256.0)

View File

@ -14,7 +14,7 @@
(def progs (def progs
(repeat 3 (:moving-to-spot test-programs/programs))) (repeat 3 (:moving-to-spot test-programs/programs)))
(def world (def world
(world/init-world 256.0 256.0 progs)) (world/init-world progs))
(defn combined-worlds [] (defn combined-worlds []
(world/build-combined-worlds world)) (world/build-combined-worlds world))
(defn worlds-for-terminal-display [fast-forward] (defn worlds-for-terminal-display [fast-forward]

View File

@ -25,7 +25,7 @@
(def progs (def progs
(repeat 3 (:moving-to-spot test-programs/programs))) (repeat 3 (:moving-to-spot test-programs/programs)))
(def world (def world
(world/init-world 256.0 256.0 progs)) (world/init-world progs))
(defn combined-worlds [] (defn combined-worlds []
(world/build-combined-worlds world)) (world/build-combined-worlds world))

View File

@ -23,13 +23,13 @@
(defn arena-text-grid (defn arena-text-grid
"outputs the arena, with borders" "outputs the arena, with borders"
[{:keys [width height robots]} print-width print-height] [{robots :robots} print-robot-range-x print-robot-range-y]
(let [horiz-border-char "-" (let [horiz-border-char "-"
vert-border-char "+" vert-border-char "+"
header-footer (apply str (repeat (+ (* print-width 3) 2) horiz-border-char)) header-footer (apply str (repeat (+ (* print-robot-range-x 3) 2) horiz-border-char))
scale-x #(* % (/ print-width width)) scale-x #(* % (/ print-robot-range-x ROBOT-RANGE-X))
scale-y #(* % (/ print-height height)) scale-y #(* % (/ print-robot-range-y ROBOT-RANGE-Y))
field (for [y (range print-height), x (range print-width)] field (for [y (range print-robot-range-y), x (range print-robot-range-x)]
(or (some (fn [{:keys [idx pos-x pos-y]}] (or (some (fn [{:keys [idx pos-x pos-y]}]
(when (near-point [(scale-x pos-x) (scale-y pos-y)] [x y]) (when (near-point [(scale-x pos-x) (scale-y pos-y)] [x y])
(str "(" idx ")"))) (str "(" idx ")")))
@ -38,7 +38,7 @@
(str header-footer (str header-footer
"\n" "\n"
(join "\n" (map #(join (apply str %) (repeat 2 vert-border-char)) (join "\n" (map #(join (apply str %) (repeat 2 vert-border-char))
(partition print-width field))) (partition print-robot-range-x field)))
"\n" "\n"
header-footer))) header-footer)))
@ -56,12 +56,12 @@
(defn animate (defn animate
"animates a sequence of worlds in the terminal" "animates a sequence of worlds in the terminal"
[initial-worlds print-width print-height fps] [initial-worlds print-robot-range-x print-robot-range-y fps]
(let [frame-period (time/millis (* (/ 1 fps) 1000)) (let [frame-period (time/millis (* (/ 1 fps) 1000))
starting-instant (time/now)] starting-instant (time/now)]
(loop [[world :as worlds] initial-worlds (loop [[world :as worlds] initial-worlds
frame-start starting-instant] frame-start starting-instant]
(println (arena-text-grid world print-width print-height)) (println (arena-text-grid world print-robot-range-x print-robot-range-y))
(display-robots-info world (time/interval starting-instant frame-start) fps) (display-robots-info world (time/interval starting-instant frame-start) fps)
(let [desired-next-frame-calc-start (time/plus frame-start frame-period) (let [desired-next-frame-calc-start (time/plus frame-start frame-period)
this-instant (time/now) this-instant (time/now)

View File

@ -1,21 +1,20 @@
(ns robotwar.world (ns robotwar.world
(:use [clojure.string :only [join]]) (:use [clojure.string :only [join]]
[robotwar.constants])
(:require [clj-time.core :as time] (:require [clj-time.core :as time]
[clj-time.periodic :as periodic] [clj-time.periodic :as periodic]
[robotwar.robot :as robot])) [robotwar.robot :as robot]))
(defn init-world (defn init-world
"initialize all the variables for a robot world." "initialize all the variables for a robot world."
[width height programs] [programs]
{:width width {:shells []
:height height
:shells []
:robots (vec (map-indexed (fn [idx program] :robots (vec (map-indexed (fn [idx program]
(robot/init-robot (robot/init-robot
idx idx
program program
{:pos-x (rand width) {:pos-x (rand ROBOT-RANGE-X)
:pos-y (rand height) :pos-y (rand ROBOT-RANGE-Y)
:aim 0.0 :aim 0.0
:damage 100.0})) :damage 100.0}))
programs))}) programs))})