From 0c988d61f415401608a004b6dabbcf7418b542ba Mon Sep 17 00:00:00 2001 From: Richard Harrington Date: Sat, 3 Aug 2013 03:38:01 -0400 Subject: [PATCH] commented out most of these high-level files till the refactoring is done --- src/robotwar/core.clj | 62 ++++++++++----------- src/robotwar/robot.clj | 119 ++++++++++++++++++++--------------------- src/robotwar/world.clj | 88 +++++++++++++++--------------- 3 files changed, 133 insertions(+), 136 deletions(-) diff --git a/src/robotwar/core.clj b/src/robotwar/core.clj index dc8907e..09a34f9 100644 --- a/src/robotwar/core.clj +++ b/src/robotwar/core.clj @@ -2,34 +2,34 @@ (:use [clojure.pprint] (robotwar foundry brain robot world game-lexicon))) -(def src-code1 " START - 0 TO A - TEST - IF A > 2 GOTO START - GOSUB INCREMENT - GOTO TEST - 100 TO A - INCREMENT - A + 1 TO A - ENDSUB - 200 TO A ") - -(def src-code2 "WAIT GOTO WAIT") -(def src-code3 "500 TO RANDOM RANDOM RANDOM RANDOM") - -(def world (init-world 30 30 (map #(assemble reg-names %) [src-code1 src-code2 src-code3]))) - -(def step (fn [initial-state n] - (nth (iterate #(tick-robot % world) initial-state) n))) - -; pretty-prints a robot-state with line numbers, -; and only the registers you want. Very convenient. - -(def ppt (fn [program n & reg-keys] - (let [state (step (init-internal-state program {}) n)] - (pprint (into (assoc-in - state - [:program :instrs] - (zipmap (range) (get-in state [:program :instrs]))) - {:registers (select-keys (:registers state) reg-keys)}))))) - +;(def src-code1 " START +; 0 TO A +; TEST +; IF A > 2 GOTO START +; GOSUB INCREMENT +; GOTO TEST +; 100 TO A +; INCREMENT +; A + 1 TO A +; ENDSUB +; 200 TO A ") +; +;(def src-code2 "WAIT GOTO WAIT") +;(def src-code3 "500 TO RANDOM RANDOM RANDOM RANDOM") +; +;(def world (init-world 30 30 (map #(assemble reg-names %) [src-code1 src-code2 src-code3]))) +; +;(def step (fn [initial-state n] +; (nth (iterate #(tick-robot % world) initial-state) n))) +; +;; pretty-prints a robot-state with line numbers, +;; and only the registers you want. Very convenient. +; +;(def ppt (fn [program n & reg-keys] +; (let [state (step (init-internal-state program {}) n)] +; (pprint (into (assoc-in +; state +; [:program :instrs] +; (zipmap (range) (get-in state [:program :instrs]))) +; {:registers (select-keys (:registers state) reg-keys)}))))) +; diff --git a/src/robotwar/robot.clj b/src/robotwar/robot.clj index a3812e9..465ce61 100644 --- a/src/robotwar/robot.clj +++ b/src/robotwar/robot.clj @@ -19,64 +19,61 @@ ; FULLY-QUALIFIED NAMES. THAT MIGHT MAKE THINGS ; A BIT CLEARER. THE NAMES CAN BE SHORTENED QUITE A BIT, ; WHEN LOADED INTO THE MODULES. - -(defn make-default-read [register] - "takes a register and returns the default version of its :read function, - which ignores the `world` parameter and just returns - the :val field from the register." - (fn [_] - (:val register))) - -(defn make-default-write [robot-idx reg-name] - "takes a robot-idx and a reg-name to locate a register, and - returns the default version of that register's :write function, - which takes a world parameter and a data value and returns the - world with the data value assoc'd into it." - (fn [world data] - (assoc-in world [:robots robot-idx :registers reg-name :val] data))) - -(def default-data 0) - -(defn default-register [robot-idx reg-name] - (init-register - reg-name - - -(defn init-robot - [program x y] - {:pos-x x - :pos-y y - :veloc-x 0 - :veloc-y 0 - :accel-x 0 - :accel-y 0 - :damage 100 - : - [let [special-registers - [init-register "X" default- - -(defn init-world - "initialize all the variables for a robot world" - [width height programs] - {:width width - :height height - :shells [] - :robots (vec (map-indexed (fn [idx program] - {:brain (init-brain - program - reg-names - {(init-register "X" - default-read - default-write - (rand-int width)) - (init-register "Y" - default-read - default-write - (rand-int height))}) - :icon (str idx)}) - programs))}) - -(defn tick-robot - [robot world] - (let [ticked (tick-brain robot world)] - )) +; +;(defn make-default-read [register] +; "takes a register and returns the default version of its :read function, +; which ignores the `world` parameter and just returns +; the :val field from the register." +; (fn [_] +; (:val register))) +; +;(defn make-default-write [robot-idx reg-name] +; "takes a robot-idx and a reg-name to locate a register, and +; returns the default version of that register's :write function, +; which takes a world parameter and a data value and returns the +; world with the data value assoc'd into it." +; (fn [world data] +; (assoc-in world [:robots robot-idx :registers reg-name :val] data))) +; +;(def default-data 0) +; +;(defn default-register [robot-idx reg-name] +; (init-register +; reg-name)) +; +; +;(defn init-robot +; [program x y] +; {:pos-x x +; :pos-y y +; :veloc-x 0 +; :veloc-y 0 +; :accel-x 0 +; :accel-y 0 +; :damage 100}) +; +;(defn init-world +; "initialize all the variables for a robot world" +; [width height programs] +; {:width width +; :height height +; :shells [] +; :robots (vec (map-indexed (fn [idx program] +; {:brain (init-brain +; program +; reg-names +; {(init-register "X" +; default-read +; default-write +; (rand-int width)) +; (init-register "Y" +; default-read +; default-write +; (rand-int height))}) +; :icon (str idx)}) +; programs))}) +; +;(defn tick-robot +; [robot world] +; (let [ticked (tick-brain robot world)] +; )) diff --git a/src/robotwar/world.clj b/src/robotwar/world.clj index 7f0fe7f..c61f8af 100644 --- a/src/robotwar/world.clj +++ b/src/robotwar/world.clj @@ -1,47 +1,47 @@ (ns robotwar.world (:use [clojure.string :only [join]] (robotwar foundry brain robot game-lexicon))) - -(defn init-world - "initialize all the variables for a robot world" - [width height programs] - {:width width - :height height - :shells [] - :robots (vec (map-indexed (fn [idx program] - {:brain (init-brain - program - reg-names - {(init-register "X" - default-read - default-write - (rand-int width)) - (init-register "Y" - default-read - default-write - (rand-int height))}) - :icon (str idx)}) - programs))}) - -(defn tick-world - "TODO" - [world-state]) - -(defn arena-text-grid - "outputs the arena, with borders" - [{:keys [width height robots]}] - (let [horiz-border-char "-" - vert-border-char "+" - header-footer (apply str (repeat (+ width 2) horiz-border-char)) - field (for [y (range height), x (range width)] - (some (fn [{{{robot-x "X" robot-y "Y"} :registers} :internal-state, icon :icon}] - (if (= [x y] [robot-x robot-y]) - icon - " ")) - robots))] - (str header-footer - "\n" - (join "\n" (map #(join (apply str %) (repeat 2 vert-border-char)) - (partition width field))) - "\n" - header-footer))) +; +;(defn init-world +; "initialize all the variables for a robot world" +; [width height programs] +; {:width width +; :height height +; :shells [] +; :robots (vec (map-indexed (fn [idx program] +; {:brain (init-brain +; program +; reg-names +; {(init-register "X" +; default-read +; default-write +; (rand-int width)) +; (init-register "Y" +; default-read +; default-write +; (rand-int height))}) +; :icon (str idx)}) +; programs))}) +; +;(defn tick-world +; "TODO" +; [world-state]) +; +;(defn arena-text-grid +; "outputs the arena, with borders" +; [{:keys [width height robots]}] +; (let [horiz-border-char "-" +; vert-border-char "+" +; header-footer (apply str (repeat (+ width 2) horiz-border-char)) +; field (for [y (range height), x (range width)] +; (some (fn [{{{robot-x "X" robot-y "Y"} :registers} :internal-state, icon :icon}] +; (if (= [x y] [robot-x robot-y]) +; icon +; " ")) +; robots))] +; (str header-footer +; "\n" +; (join "\n" (map #(join (apply str %) (repeat 2 vert-border-char)) +; (partition width field))) +; "\n" +; header-footer)))