[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Code Chapter 5 of LandOfLisp, with the modifications discussed below.
Report the REPL log (described below) from running rwalk!-worker (see below) and all the lisp files you created or modified.
You may need to know about the following LISP commands (see Graham):
dolist, dotimes, list, append, let, let*, if, when, unless, setf, mapcar, lambda
.
Create random landscapes using (landscape n f1 f2)
where n
is the number of nodes and
f1,f2
are the min to max fanout from a room
(number of rooms connecting to this one).
Internally, landscape
will rewrite the
*edges*
and
*nodes*
and *objects*
and *objects-location*
variables.
To do this, create the random *nodes* first
then, create random edges by selecting f1
to f1
nodes, at random.
To select the right number of nodes from the fanout, use
(defun within (x y) (+ x (* (- y x) (randf 1.0)))) (round (within f1 f2))
To create random node names, e.g. use (gensym "garden")
. To
create random descriptions, just use (format nil "You are in
~a.~%" nodeName)
. To add the new node to *objects*
using
(push newnode *nodes*)
.
To pull a random node, use
(defun any (alist) (nth (randi (length alist)) alist)) (any *nodes*)
To create random objects, use e.g. (gensym "sword")
then
put them into randomly selected rooms.
Write a random walk routine that walks around the random landscape, picking up everything it encounters, everywhere:
(defun !rwalk-worker (&optional (rooms 20) (f1 1) (f2 5) (steps 100)) (reset-seed) (landscape 20 1 5) (format t "nodes: ~a~%~%edges: ~a~%~%objects: ~a~%~%at: ~a~%~%" *nodes* *edges* *objects* *object-locations*) (dotimes (i steps) (rwalk)) (inventory))
Write a deftest
that uses !rwalk-worker
that checks for the right inventory output.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on March 1, 2011 using texi2html 5.0.