rearranged dependencies so that all calls to foundry/assemble are made from brain/init-brain, and higher levels pass in source code to init/brain

This commit is contained in:
Richard Harrington 2013-08-04 21:36:33 -04:00
parent 63d678f406
commit 37deec17de
2 changed files with 9 additions and 6 deletions

View File

@ -1,7 +1,9 @@
(ns robotwar.brain
(:use [clojure.string :only [join]]
[clojure.pprint :only [pprint]])
(:require [robotwar.kernel-lexicon]))
(:require (robotwar kernel-lexicon
game-lexicon
foundry)))
(def op-map (into {} (for [op robotwar.kernel-lexicon/op-commands]
[op (case op
@ -27,11 +29,13 @@
"initialize the brain, meaning all the internal state variables that go along
with the robot program when it's running, except for the registers,
which are queried from the robot."
[program]
[src-code]
{:acc 0
:instr-ptr 0
:call-stack []
:program program})
:program (robotwar.foundry/assemble
robotwar.game-lexicon/reg-names
src-code)})
(defn resolve-arg [{arg-val :val arg-type :type} registers labels world]
"resolves an instruction argument to a numeric value

View File

@ -1,7 +1,7 @@
(ns robotwar.brain-test
(:use [clojure.test]
[robotwar.brain])
(:require (robotwar foundry game-lexicon)))
(:require [robotwar.game-lexicon]))
(def src-codes [ ; program 0: multi-use program
" START
@ -39,8 +39,7 @@
(assoc-in world path-to-val data))
:val 0}})))))
(def brains (map (comp init-brain (partial robotwar.foundry/assemble robotwar.game-lexicon/reg-names))
src-codes))
(def brains (map init-brain src-codes))
(def robots (vec (map (fn [idx brain robot-registers]
{:idx idx