1 (in-package #:cl-nl.nvm)
3 ; This is the engine. Yay.
5 (defvar *current-id* 0)
7 (defstruct turtle who color heading xcor ycor)
13 (format t "Showing: ~A~%" n))
15 (defun create-turtle ()
17 (make-turtle :who *current-id*
18 :color (coerce (+ 5 (* 10 (cl-nl.random:next-int 14))) 'double-float)
19 :heading (coerce (cl-nl.random:next-int 360) 'double-float)
25 (defun turtles () *turtles*)
27 (defun ask (agent-set fn)
36 (defun shuffle (agent-set)
38 ((copy (copy-list agent-set)))
40 (loop for i to (- (length copy) 2)
41 for idx = (+ i (cl-nl.random:next-int (- (length copy) i)))
42 for next = (nth idx copy)
43 do (setf (nth idx copy) (nth i copy))
48 (when (not (turtle-p *self*)) (error "Gotta call fd in turtle scope, dude"))
49 (setf (turtle-xcor *self*) (+ (turtle-xcor *self*) (sin (* pi (/ (turtle-heading *self*) 180)))))
50 (setf (turtle-ycor *self*) (+ (turtle-ycor *self*) (cos (* pi (/ (turtle-heading *self*) 180))))))
52 (defun create-turtles (n)
53 (loop for i from 1 to n do (create-turtle)))
55 (defun create-world ()
57 (setf *current-id* 0))
60 (multiple-value-bind (int rem) (floor n)
63 (format nil "~F" n))))
65 (defun export-world ()
66 (format nil "~{~A~%~}"
68 (format nil "~S" "RANDOM STATE")
69 (format nil "~S" (cl-nl.random:export))
71 (format nil "~S" "GLOBALS")
72 "\"min-pxcor\",\"max-pxcor\",\"min-pycor\",\"max-pycor\",\"perspective\",\"subject\",\"nextIndex\",\"directed-links\",\"ticks\","
73 (format nil "\"-1\",\"1\",\"-1\",\"1\",\"0\",\"nobody\",\"~A\",\"\"\"NEITHER\"\"\",\"-1\"" *current-id*)
75 (format nil "~S" "TURTLES")
76 "\"who\",\"color\",\"heading\",\"xcor\",\"ycor\",\"shape\",\"label\",\"label-color\",\"breed\",\"hidden?\",\"size\",\"pen-size\",\"pen-mode\""
77 (format nil "~{~A~%~}"
81 "\"~A\",\"~A\",\"~A\",\"~A\",\"~A\",\"\"\"default\"\"\",\"\"\"\"\"\",\"9.9\",\"{all-turtles}\",\"false\",\"1\",\"1\",\"\"\"up\"\"\""
83 (format-num (turtle-color turtle))
84 (format-num (turtle-heading turtle))
85 (format-num (turtle-xcor turtle))
86 (format-num (turtle-ycor turtle))
89 (format nil "~S" "PATCHES")
90 "\"pxcor\",\"pycor\",\"pcolor\",\"plabel\",\"plabel-color\""
91 "\"-1\",\"1\",\"0\",\"\"\"\"\"\",\"9.9\""
92 "\"0\",\"1\",\"0\",\"\"\"\"\"\",\"9.9\""
93 "\"1\",\"1\",\"0\",\"\"\"\"\"\",\"9.9\""
94 "\"-1\",\"0\",\"0\",\"\"\"\"\"\",\"9.9\""
95 "\"0\",\"0\",\"0\",\"\"\"\"\"\",\"9.9\""
96 "\"1\",\"0\",\"0\",\"\"\"\"\"\",\"9.9\""
97 "\"-1\",\"-1\",\"0\",\"\"\"\"\"\",\"9.9\""
98 "\"0\",\"-1\",\"0\",\"\"\"\"\"\",\"9.9\""
99 "\"1\",\"-1\",\"0\",\"\"\"\"\"\",\"9.9\""
101 (format nil "~S" "LINKS")
102 "\"end1\",\"end2\",\"color\",\"label\",\"label-color\",\"hidden?\",\"breed\",\"thickness\",\"shape\",\"tie-mode\""