From: Frank Duncan Date: Sun, 7 Jun 2015 06:11:28 +0000 (-0500) Subject: Creating a few turtles X-Git-Tag: v0.0.0~15 X-Git-Url: https://code.consxy.com/gitweb/gitweb.cgi?a=commitdiff_plain;h=a4cc3c4533c1745362078c607e34e3448ac4feb4;p=clnl Creating a few turtles --- diff --git a/src/main/main.lisp b/src/main/main.lisp index 6ae3bc0..f5a47b0 100644 --- a/src/main/main.lisp +++ b/src/main/main.lisp @@ -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))))) diff --git a/src/main/nvm.lisp b/src/main/nvm.lisp index 3ea76d9..011eb6d 100644 --- a/src/main/nvm.lisp +++ b/src/main/nvm.lisp @@ -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~%~}" @@ -13,11 +36,19 @@ "" (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\"" diff --git a/src/main/package.lisp b/src/main/package.lisp index 642d2f0..ff2f077 100644 --- a/src/main/package.lisp +++ b/src/main/package.lisp @@ -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)) - diff --git a/src/test/simpletests.lisp b/src/test/simpletests.lisp index 6cfd668..55aee65 100644 --- a/src/test/simpletests.lisp +++ b/src/test/simpletests.lisp @@ -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")