Creating a few turtles
authorFrank Duncan <frank@kank.net>
Sun, 7 Jun 2015 06:11:28 +0000 (01:11 -0500)
committerFrank Duncan <frank@kank.net>
Sun, 7 Jun 2015 06:11:28 +0000 (01:11 -0500)
src/main/main.lisp
src/main/nvm.lisp
src/main/package.lisp
src/test/simpletests.lisp

index 6ae3bc0ff10c70341d2506cbf56cdb3215167d83..f5a47b0627dce17fcbb231abd26ba2cc527f3d16 100644 (file)
@@ -17,7 +17,9 @@
        do (p (e (r str)))))
 
 (defun boot ()
- (cl-nl.random:set-seed 15))
+ (cl-nl.random:set-seed 15)
+ (cl-nl.nvm:create-world)
+ )
 
 (defun run-commands (cmds)
  (eval (cl-nl.transpiler:transpile-command-block (cl-nl.parser:parse  (cl-nl.lexer:lex cmds)))))
index 3ea76d9309c681662c6f35e686348dc8212fc812..011eb6d8158c9ce1452f3cabf422bf5352b47c79 100644 (file)
@@ -2,8 +2,31 @@
 
 ; This is the engine.  Yay.
 
+(defvar *current-id* 0)
+
+(defstruct turtle who color heading)
+(defvar *turtles* nil)
+
+(defun create-turtle ()
+ (push
+  (make-turtle :who *current-id*
+               :color (coerce (+ 5 (* 10 (cl-nl.random:next-int 14))) 'double-float)
+               :heading (coerce (cl-nl.random:next-int 360) 'double-float))
+  *turtles*)
+ (incf *current-id*))
+
 (defun create-turtles (n)
- (format t "HELLO WORLD ~A~%" n))
+ (loop for i from 1 to n do (create-turtle)))
+
+(defun create-world ()
+ (setf *turtles* nil)
+ (setf *current-id* 0))
+
+(defun format-num (n)
+ (multiple-value-bind (int rem) (floor n)
+  (if (eql 0d0 rem)
+      (format nil "~A" int)
+      (format nil "~F" n))))
 
 (defun export-world ()
  (format nil "~{~A~%~}"
    ""
    (format nil "~S" "GLOBALS")
    "\"min-pxcor\",\"max-pxcor\",\"min-pycor\",\"max-pycor\",\"perspective\",\"subject\",\"nextIndex\",\"directed-links\",\"ticks\","
-   "\"-1\",\"1\",\"-1\",\"1\",\"0\",\"nobody\",\"0\",\"\"\"NEITHER\"\"\",\"-1\""
+   (format nil "\"-1\",\"1\",\"-1\",\"1\",\"0\",\"nobody\",\"~A\",\"\"\"NEITHER\"\"\",\"-1\"" *current-id*)
    ""
    (format nil "~S" "TURTLES")
    "\"who\",\"color\",\"heading\",\"xcor\",\"ycor\",\"shape\",\"label\",\"label-color\",\"breed\",\"hidden?\",\"size\",\"pen-size\",\"pen-mode\""
-   ""
+   (format nil "~{~A~%~}"
+    (mapcar
+     (lambda (turtle)
+      (format nil
+       "\"~A\",\"~A\",\"~A\",\"0\",\"0\",\"\"\"default\"\"\",\"\"\"\"\"\",\"9.9\",\"{all-turtles}\",\"false\",\"1\",\"1\",\"\"\"up\"\"\""
+       (turtle-who turtle)
+       (format-num (turtle-color turtle))
+       (format-num (turtle-heading turtle))))
+     (reverse *turtles*)))
    (format nil "~S" "PATCHES")
    "\"pxcor\",\"pycor\",\"pcolor\",\"plabel\",\"plabel-color\""
    "\"-1\",\"1\",\"0\",\"\"\"\"\"\",\"9.9\""
index 642d2f00668455e3fddfff718fcf698303d9123e..ff2f077bc0203d5ef95a7d3c6e6a41430c43315c 100644 (file)
@@ -16,9 +16,8 @@
 
 (defpackage #:cl-nl.nvm
  (:use :common-lisp)
- (:export :export-world))
+ (:export :export-world :create-world))
 
 (defpackage #:cl-nl.lexer
  (:use :common-lisp)
  (:export :lex))
-
index 6cfd66832b82926d704c0285e52b5a12c2f129b8..55aee65e7e7165ad9c15362758e0680f853927a9 100644 (file)
@@ -1,4 +1,5 @@
 (in-package #:cl-nl-test)
 
 (defsimpletest "Nothing" "" "E1DE30F072D785E0D0B59F28B0F7853E3D3E0D8B")
-;(defsimpletest "Simple crt" "crt 1" "F6D10F42CDC9F0EE28F54D9DF26729C0D8591E60 0")
+(defsimpletest "Simple crt" "crt 1" "2F08B31AC06C9D5339E6B3E953C2B4B71FDB9CDE")
+(defsimpletest "Simple crt 2" "crt 5" "9FE588C2749CD9CE66CB0EA451EFB80476E881FB")