Coverage report: /Users/mohacker/src/yurrriq/land-of-lisp/src/wumpus.lisp
Kind | Covered | All | % |
expression | 0 | 204 | 0.0 |
branch | 0 | 18 | 0.0 |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
4
(in-package :lol.wumpus)
7
;; TODO: (load "graph-util")
10
(defparameter *congestion-city-nodes* nil)
11
(defparameter *congestion-city-edges* nil)
12
(defparameter *visited-nodes* nil)
13
(defparameter *node-num* 30 )
14
(defparameter *edge-num* 45)
15
(defparameter *worm-num* 3)
16
(defparameter *cop-odds* 15)
20
(1+ (random *node-num*)))
23
(defun edge-pair (a b)
25
(list (cons a b) (cons b a))))
28
(defun make-edge-list ()
29
(apply #'append (loop repeat *edge-num*
30
collect (edge-pair (random-node) (random-node)))))
33
(defun direct-edges (node edge-list)
34
(remove-if-not (lambda (x)
39
(defun get-connected (node edge-list)
41
(labels ((traverse (node)
42
(unless (member node visited)
45
(traverse (cdr edge)))
46
(direct-edges node edge-list)))))
51
(defun find-islands (nodes edge-list)
53
(labels ((find-island (nodes)
54
(let* ((connected (get-connected (car nodes) edge-list))
55
(unconnected (set-difference nodes connected)))
56
(push connected islands)
58
(find-island unconnected)))))
63
(defun connect-with-bridges (islands)
65
(append (edge-pair (caar islands) (caadr islands))
66
(connect-with-bridges (cdr islands)))))
69
(defun connect-all-islands (nodes edge-list)
70
(append (connect-with-bridges (find-islands nodes edge-list)) edge-list))
73
(defun make-city-edges ()
74
(let* ((nodes (loop for i from 1 to *node-num*
76
(edge-list (connect-all-islands nodes (make-edge-list)))
77
(cops (remove-if-not (lambda (x)
78
(zerop (random *cop-odds*)))
80
(add-cops (edges-to-alist edge-list) cops)))
83
(defun edges-to-alist (edge-list)
84
(mapcar (lambda (node1)
86
(mapcar (lambda (edge)
88
(remove-duplicates (direct-edges node1 edge-list)
90
(remove-duplicates (mapcar #'car edge-list))))
93
(defun add-cops (edge-alist edges-with-cops)
96
(node1-edges (cdr x)))
98
(mapcar (lambda (edge)
99
(let ((node2 (car edge)))
100
(if (intersection (edge-pair node1 node2)
109
(defun neighbors (node edge-alist)
110
(mapcar #'car (cdr (assoc node edge-alist))))
113
(defun within-one (a b edge-alist)
114
(member b (neighbors a edge-alist)))
117
(defun within-two (a b edge-alist)
118
(or (within-one a b edge-alist)
120
(within-one x b edge-alist))
121
(neighbors a edge-alist))))
124
(defun make-city-nodes (edge-alist)
125
(let ((wumpus (random-node))
126
(glow-worms (loop for i below *worm-num*
127
collect (random-node))))
128
(loop for n from 1 to *node-num*
129
collect (append (list n)
130
(cond ((eql n wumpus) '(wumpus))
131
((within-two n wumpus edge-alist) '(blood!)))
132
(cond ((member n glow-worms)
134
((some (lambda (worm)
135
(within-one n worm edge-alist))
138
(when (some #'cdr (cdr (assoc n edge-alist)))