1 (in-package #:clnl-nvm)
3 (defun export-turtles ()
7 (format nil "~A~A~{,\"~A\"~}"
8 "\"who\",\"color\",\"heading\",\"xcor\",\"ycor\",\"shape\",\"label\",\"label-color\","
9 "\"breed\",\"hidden?\",\"size\",\"pen-size\",\"pen-mode\""
10 (mapcar #'string-downcase *turtles-own-vars*)))
14 "\"~A\",\"~A\",\"~A\",\"~A\",\"~A\",\"~A\",\"~A\",\"~A\",\"~A\",\"false\",\"~A\",~A~{,\"~A\"~}"
15 (dump-object (turtle-who turtle))
16 (dump-object (turtle-color turtle))
17 (dump-object (turtle-heading turtle))
18 (dump-object (turtle-xcor turtle))
19 (dump-object (turtle-ycor turtle))
20 (dump-object (turtle-shape turtle))
21 (dump-object (turtle-label turtle))
22 (dump-object (turtle-label-color turtle))
23 (dump-object (turtle-breed turtle))
24 (dump-object (turtle-size turtle))
25 "\"1\",\"\"\"up\"\"\""
26 (mapcar #'dump-object (mapcar (lambda (var) (agent-value-inner turtle var)) *turtles-own-vars*))))
29 (defun export-patches ()
33 (format nil "\"pxcor\",\"pycor\",\"pcolor\",\"plabel\",\"plabel-color\"~{,\"~A\"~}"
34 (mapcar #'string-downcase *patches-own-vars*)))
38 "\"~A\",\"~A\",\"~A\",\"\"\"\"\"\",\"9.9\"~{,\"~A\"~}"
39 (dump-object (patch-xcor patch))
40 (dump-object (patch-ycor patch))
41 (dump-object (patch-color patch))
42 (mapcar #'dump-object (mapcar (lambda (var) (agent-value-inner patch var)) *patches-own-vars*))))
45 (defun export-world ()
46 "EXPORT-WORLD => WORLD-CSV
50 WORLD-CSV: A string, the csv of the world
54 Dumps out a csv matching NetLogo's export world.
56 This is useful for serializing the current state of the engine in order
57 to compare against NetLogo or to reimport later. Contains everything needed
58 to boot up a NetLogo instance in the exact same state."
60 ((ordered-globals (sort (copy-list *globals*) #'string< :key (lambda (global) (symbol-name (car global))))))
61 (format nil "~{~A~%~}"
63 (format nil "~S" "RANDOM STATE")
64 (format nil "~S" (clnl-random:export))
66 (format nil "~S" "GLOBALS")
67 (format nil "~A~A~{\"~A\"~^,~}"
68 "\"min-pxcor\",\"max-pxcor\",\"min-pycor\",\"max-pycor\",\"perspective\",\"subject\","
69 "\"nextIndex\",\"directed-links\",\"ticks\","
70 (mapcar #'string-downcase (mapcar #'car ordered-globals)))
71 (format nil "\"~A\",\"~A\",\"~A\",\"~A\",\"0\",\"nobody\",\"~A\",\"\"\"NEITHER\"\"\",\"~A\"~{,\"~A\"~}"
72 (min-pxcor) (max-pxcor) (min-pycor) (max-pycor) *current-id* (dump-object (or *ticks* -1d0))
73 (mapcar #'dump-object (mapcar #'funcall (mapcar #'cadr ordered-globals))))
75 (format nil "~{~A~^~%~}" (export-turtles))
77 (format nil "~{~A~^~%~}" (export-patches))
79 (format nil "~S" "LINKS")
80 "\"end1\",\"end2\",\"color\",\"label\",\"label-color\",\"hidden?\",\"breed\",\"thickness\",\"shape\",\"tie-mode\""
88 VALUE: a NetLogo value
93 A command that prints the given NetLogo value to the command center.
95 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#show"
96 (format t "Showing: ~A~%" (dump-object value)))