November 2010
Intermediate to advanced
504 pages
12h 45m
English
Now we’ll build an alist for the nodes in our city. These nodes may contain the Wumpus or the Glowworms, or they might contain various clues, such as blood, lights, or sirens.
Most of the clues in our game are based on proximity to another node, so we need to write some functions that tell us if two nodes are one node apart in the city graph. The neighbors function looks up the node’s neighbors using the alist of edges. If the second node is in that list, we know we’re one away.
(defun neighbors (node edge-alist) (mapcar #'car (cdr (assoc node edge-alist)))) (defun within-one (a b edge-alist) (member b (neighbors a edge-alist)))
First, this function looks up the first node (a) in the alist of edges with neighbors ...
Read now
Unlock full access