2013-07-29 02:34:53 +00:00
|
|
|
(ns robotwar.core
|
2013-08-14 20:37:35 +00:00
|
|
|
(:use [clojure.pprint :only [pprint]])
|
2013-08-20 16:21:09 +00:00
|
|
|
(:require [robotwar.source-programs :as source-programs]
|
2013-08-06 15:34:51 +00:00
|
|
|
[robotwar.world :as world]
|
2013-08-15 20:22:00 +00:00
|
|
|
[robotwar.register :as register]
|
|
|
|
[robotwar.robot :as robot]
|
2013-08-20 15:40:29 +00:00
|
|
|
[robotwar.terminal :as terminal]
|
|
|
|
[robotwar.browser :as browser]))
|
2013-07-25 16:53:10 +00:00
|
|
|
|
2013-08-10 02:01:56 +00:00
|
|
|
; this is a hacky place for messing with stuff.
|
|
|
|
|
2013-08-06 22:01:57 +00:00
|
|
|
|
2013-08-15 20:22:00 +00:00
|
|
|
|
2013-08-17 03:47:46 +00:00
|
|
|
(def progs
|
2013-08-24 10:37:49 +00:00
|
|
|
(repeat 3 (:mover source-programs/dev-programs)))
|
2013-08-17 03:47:46 +00:00
|
|
|
(def world
|
2013-08-20 16:10:58 +00:00
|
|
|
(world/init-world progs))
|
2013-08-17 03:26:34 +00:00
|
|
|
(defn combined-worlds []
|
2013-08-17 03:47:46 +00:00
|
|
|
(world/build-combined-worlds world))
|
2013-08-17 19:51:10 +00:00
|
|
|
(defn worlds-for-terminal-display [fast-forward]
|
2013-08-20 15:40:29 +00:00
|
|
|
(terminal/worlds-for-terminal (combined-worlds) fast-forward))
|
2013-08-17 03:34:30 +00:00
|
|
|
(defn make-it-so [fast-forward fps]
|
2013-08-20 15:40:29 +00:00
|
|
|
(terminal/animate (worlds-for-terminal-display fast-forward) 25 25 fps))
|
2013-08-17 19:51:10 +00:00
|
|
|
|
2013-08-17 19:51:45 +00:00
|
|
|
(defn worlds-for-browser-display []
|
2013-08-20 15:40:29 +00:00
|
|
|
(browser/worlds-for-browser (combined-worlds)))
|
2013-08-15 20:22:00 +00:00
|
|
|
|
2013-08-07 15:36:03 +00:00
|
|
|
(def rr register/read-register)
|
|
|
|
(def wr register/write-register)
|
2013-08-06 22:01:57 +00:00
|
|
|
|
|
|
|
; ppt uses some of those variables to
|
2013-08-05 02:48:13 +00:00
|
|
|
; pretty-print a robot-state with line numbers for the obj-code instructions,
|
2013-08-03 17:52:10 +00:00
|
|
|
; and only the registers you want. Very convenient.
|
2013-08-03 07:38:01 +00:00
|
|
|
;
|
2013-08-03 17:52:10 +00:00
|
|
|
; it takes a world-tick number and a robot index number, and prettyprints a robot
|
2013-08-05 02:48:13 +00:00
|
|
|
; with line numbers for the obj-code instructions, and only the registers specified.
|
2013-08-10 04:55:17 +00:00
|
|
|
; Very convenient.
|
2013-08-03 17:52:10 +00:00
|
|
|
|
2013-08-10 19:55:26 +00:00
|
|
|
|
2013-08-20 21:01:42 +00:00
|
|
|
(defn pprint-robot
|
|
|
|
[robot & reg-keys]
|
|
|
|
(let [{{registers :registers, {instrs :instrs} :obj-code} :brain :as robot} robot
|
|
|
|
registers-to-print (if reg-keys
|
|
|
|
(select-keys registers reg-keys)
|
|
|
|
registers)]
|
|
|
|
(pprint
|
|
|
|
(assoc-in
|
|
|
|
(assoc-in robot [:brain :registers] registers-to-print)
|
|
|
|
[:brain :obj-code :instrs]
|
|
|
|
(sort (zipmap (range) instrs))))))
|
|
|
|
|
|
|
|
(defn pprint-robot-at-combined-world
|
|
|
|
[combined-worlds world-idx robot-idx & reg-keys]
|
|
|
|
(apply pprint-robot
|
|
|
|
(get-in (nth combined-worlds world-idx) [:robots robot-idx])
|
|
|
|
reg-keys))
|
2013-08-17 03:49:03 +00:00
|
|
|
|
|
|
|
(def ppr pprint-robot)
|
|
|
|
(def pprw pprint-robot-at-combined-world)
|