aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Oteiza2017-03-19 22:21:03 -0400
committerMark Oteiza2017-03-19 22:21:03 -0400
commit34d69ed7355572b905bf16ab84024b7056cffe85 (patch)
tree6526014e73edfc8281da3d0a7de8c858c9709547
parent715962e5c416b62c1deea0bec16c88ae9c63674e (diff)
downloademacs-34d69ed7355572b905bf16ab84024b7056cffe85.tar.gz
emacs-34d69ed7355572b905bf16ab84024b7056cffe85.zip
Simpler filter implementation
* lisp/play/dunnet.el (dun-endgame-question): Get or set dun-endgame-questions one time only. Use dolist and an index to prune the list.
-rw-r--r--lisp/play/dunnet.el39
1 files changed, 17 insertions, 22 deletions
diff --git a/lisp/play/dunnet.el b/lisp/play/dunnet.el
index 677946262c5..8f013bb09f2 100644
--- a/lisp/play/dunnet.el
+++ b/lisp/play/dunnet.el
@@ -2106,28 +2106,23 @@ for a moment, then straighten yourself up.\n")
2106 (dun-mprincl "That answer is incorrect."))))) 2106 (dun-mprincl "That answer is incorrect.")))))
2107 2107
2108(defun dun-endgame-question () 2108(defun dun-endgame-question ()
2109(if (not dun-endgame-questions) 2109 (let ((questions dun-endgame-questions))
2110 (progn 2110 (if (null questions)
2111 (dun-mprincl "Your question is:") 2111 (progn
2112 (dun-mprincl "No more questions, just do ‘answer foo’.") 2112 (dun-mprincl "Your question is:")
2113 (setq dun-correct-answer '("foo"))) 2113 (dun-mprincl "No more questions, just do ‘answer foo’.")
2114 (let (which i newques) 2114 (setq dun-correct-answer '("foo")))
2115 (setq i 0) 2115 (let* ((which (random (length questions)))
2116 (setq newques nil) 2116 (question (nth which questions)))
2117 (setq which (random (length dun-endgame-questions))) 2117 (dun-mprincl "Your question is:")
2118 (dun-mprincl "Your question is:") 2118 (dun-mprincl (setq dun-endgame-question (car question)))
2119 (dun-mprincl (setq dun-endgame-question (car 2119 (setq dun-correct-answer (cdr question))
2120 (nth which 2120 (let ((i 0) res)
2121 dun-endgame-questions)))) 2121 (dolist (q questions)
2122 (setq dun-correct-answer (cdr (nth which dun-endgame-questions))) 2122 (when (/= i which)
2123 (while (< i which) 2123 (push q res))
2124 (setq newques (append newques (list (nth i dun-endgame-questions)))) 2124 (setq i (1+ i)))
2125 (setq i (1+ i))) 2125 (setq dun-endgame-questions (nreverse res)))))))
2126 (setq i (1+ which))
2127 (while (< i (length dun-endgame-questions))
2128 (setq newques (append newques (list (nth i dun-endgame-questions))))
2129 (setq i (1+ i)))
2130 (setq dun-endgame-questions newques))))
2131 2126
2132(defun dun-power (_args) 2127(defun dun-power (_args)
2133 (if (not (= dun-current-room pc-area)) 2128 (if (not (= dun-current-room pc-area))