Creating a few turtles
[clnl] / src / main / nvm.lisp
1 (in-package #:cl-nl.nvm)
2
3 ; This is the engine.  Yay.
4
5 (defvar *current-id* 0)
6
7 (defstruct turtle who color heading)
8 (defvar *turtles* nil)
9
10 (defun create-turtle ()
11  (push
12   (make-turtle :who *current-id*
13                :color (coerce (+ 5 (* 10 (cl-nl.random:next-int 14))) 'double-float)
14                :heading (coerce (cl-nl.random:next-int 360) 'double-float))
15   *turtles*)
16  (incf *current-id*))
17
18 (defun create-turtles (n)
19  (loop for i from 1 to n do (create-turtle)))
20
21 (defun create-world ()
22  (setf *turtles* nil)
23  (setf *current-id* 0))
24
25 (defun format-num (n)
26  (multiple-value-bind (int rem) (floor n)
27   (if (eql 0d0 rem)
28       (format nil "~A" int)
29       (format nil "~F" n))))
30
31 (defun export-world ()
32  (format nil "~{~A~%~}"
33   (list
34    (format nil "~S" "RANDOM STATE")
35    (format nil "~S" (cl-nl.random:export))
36    ""
37    (format nil "~S" "GLOBALS")
38    "\"min-pxcor\",\"max-pxcor\",\"min-pycor\",\"max-pycor\",\"perspective\",\"subject\",\"nextIndex\",\"directed-links\",\"ticks\","
39    (format nil "\"-1\",\"1\",\"-1\",\"1\",\"0\",\"nobody\",\"~A\",\"\"\"NEITHER\"\"\",\"-1\"" *current-id*)
40    ""
41    (format nil "~S" "TURTLES")
42    "\"who\",\"color\",\"heading\",\"xcor\",\"ycor\",\"shape\",\"label\",\"label-color\",\"breed\",\"hidden?\",\"size\",\"pen-size\",\"pen-mode\""
43    (format nil "~{~A~%~}"
44     (mapcar
45      (lambda (turtle)
46       (format nil
47        "\"~A\",\"~A\",\"~A\",\"0\",\"0\",\"\"\"default\"\"\",\"\"\"\"\"\",\"9.9\",\"{all-turtles}\",\"false\",\"1\",\"1\",\"\"\"up\"\"\""
48        (turtle-who turtle)
49        (format-num (turtle-color turtle))
50        (format-num (turtle-heading turtle))))
51      (reverse *turtles*)))
52    (format nil "~S" "PATCHES")
53    "\"pxcor\",\"pycor\",\"pcolor\",\"plabel\",\"plabel-color\""
54    "\"-1\",\"1\",\"0\",\"\"\"\"\"\",\"9.9\""
55    "\"0\",\"1\",\"0\",\"\"\"\"\"\",\"9.9\""
56    "\"1\",\"1\",\"0\",\"\"\"\"\"\",\"9.9\""
57    "\"-1\",\"0\",\"0\",\"\"\"\"\"\",\"9.9\""
58    "\"0\",\"0\",\"0\",\"\"\"\"\"\",\"9.9\""
59    "\"1\",\"0\",\"0\",\"\"\"\"\"\",\"9.9\""
60    "\"-1\",\"-1\",\"0\",\"\"\"\"\"\",\"9.9\""
61    "\"0\",\"-1\",\"0\",\"\"\"\"\"\",\"9.9\""
62    "\"1\",\"-1\",\"0\",\"\"\"\"\"\",\"9.9\""
63    ""
64    (format nil "~S" "LINKS")
65    "\"end1\",\"end2\",\"color\",\"label\",\"label-color\",\"hidden?\",\"breed\",\"thickness\",\"shape\",\"tie-mode\""
66    ""
67    )))