+ "CREATE-TURTLES N => RESULT
+
+ARGUMENTS AND VALUES:
+
+ N: an integer, the numbers of turtles to create
+ RESULT: undefined
+
+DESCRIPTION:
+
+ Creates number new turtles at the origin.
+
+ New turtles have random integer headings and the color is randomly selected
+ from the 14 primary colors. If commands are supplied, the new turtles
+ immediately run them (unimplemented).
+
+ See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#create-turtles"
+ (loop :for i :from 1 :to n :do (create-turtle)))
+
+(defun create-world (model)
+ "CREATE-WORLD MODEL => RESULT
+
+ARGUMENTS AND VALUES:
+
+ MODEL: A clnl-model:model to use to initialize the vm
+ RESULT: undefined
+
+DESCRIPTION:
+
+ Initializes the world in the NVM.
+
+ This should be called before using the engine in any real capacity. If
+ called when an engine is already running, it may do somethign weird."
+ (setf *model* model)
+ (setf *turtles* nil)
+ (setf *current-id* 0))
+
+; These match netlogo's dump
+(defgeneric dump-object (o))
+
+(defmethod dump-object ((n double-float))
+ (multiple-value-bind (int rem) (floor n)
+ (if (eql 0d0 rem)
+ (format nil "~A" int)
+ (let
+ ((output (format nil "~D" n)))
+ ; Someday we'll have d<posint>, but this is not that day!
+ (cl-ppcre:regex-replace "d-" (cl-ppcre:regex-replace "d0" output "") "E-")))))
+
+(defmethod dump-object ((o string)) o)
+
+(defun current-state ()
+ "CURRENT-STATE => WORLD-STATE
+
+ARGUMENTS AND VALUES:
+
+ WORLD-STATE: A list, the current state of the whole world
+
+DESCRIPTION:
+
+ Dumps out the state of the world.
+
+ This is useful for visualizations and also storing in a common lisp
+ data structure for easy usage in a common lisp instance. It's preferable
+ to use this when working with the nvm than the output done by export-world.
+
+ Currently this only dumps out turtle information.
+
+ This is called CURRENT-STATE because export-world is an actual primitive
+ used by NetLogo."
+ (mapcar
+ (lambda (turtle)
+ (list
+ :color (turtle-color turtle)
+ :xcor (turtle-xcor turtle)
+ :ycor (turtle-ycor turtle)
+ :heading (turtle-heading turtle)))
+ *turtles*))
+
+(defun export-patches ()
+ (list
+ "\"pxcor\",\"pycor\",\"pcolor\",\"plabel\",\"plabel-color\""
+ "\"-1\",\"1\",\"0\",\"\"\"\"\"\",\"9.9\""
+ "\"0\",\"1\",\"0\",\"\"\"\"\"\",\"9.9\""
+ "\"1\",\"1\",\"0\",\"\"\"\"\"\",\"9.9\""
+ "\"-1\",\"0\",\"0\",\"\"\"\"\"\",\"9.9\""
+ "\"0\",\"0\",\"0\",\"\"\"\"\"\",\"9.9\""
+ "\"1\",\"0\",\"0\",\"\"\"\"\"\",\"9.9\""
+ "\"-1\",\"-1\",\"0\",\"\"\"\"\"\",\"9.9\""
+ "\"0\",\"-1\",\"0\",\"\"\"\"\"\",\"9.9\""
+ "\"1\",\"-1\",\"0\",\"\"\"\"\"\",\"9.9\""))