robotwar/src/robotwar/world.clj
Richard Harrington 9b46900f9b 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
2013-08-20 12:10:58 -04:00

30 lines
1.0 KiB
Clojure

(ns robotwar.world
(:use [clojure.string :only [join]]
[robotwar.constants])
(:require [clj-time.core :as time]
[clj-time.periodic :as periodic]
[robotwar.robot :as robot]))
(defn init-world
"initialize all the variables for a robot world."
[programs]
{:shells []
:robots (vec (map-indexed (fn [idx program]
(robot/init-robot
idx
program
{:pos-x (rand ROBOT-RANGE-X)
:pos-y (rand ROBOT-RANGE-Y)
:aim 0.0
:damage 100.0}))
programs))})
(defn tick-combined-world
[starting-world]
(reduce (fn [{robots :robots :as world} robot-idx]
(robot/step-robot (robots robot-idx) world))
starting-world
(range (count (:robots starting-world)))))
(def build-combined-worlds (partial iterate tick-combined-world))