Building the Nodes for Congestion City

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 ...

Get Land of Lisp now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.