diff options
author | Grant Shangreaux <grant@unabridgedsoftware.com> | 2022-01-22 14:16:58 -0600 |
---|---|---|
committer | Grant Shangreaux <grant@unabridgedsoftware.com> | 2022-01-22 14:16:58 -0600 |
commit | 5d8180f0c6bfd690e1b1265e11ef8900d94fa36c (patch) | |
tree | 2ff220ea013b23ada0291ef76125d13167e1f0a5 | |
parent | 7879a9a52bd35254a72db4f310b121911a5c2dcb (diff) |
Add: minor change to example code, use with-slots
-rw-r--r-- | mafia.org | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -128,28 +128,27 @@ Lets initialize a game with 6 actors and inspect it to see what to expect. #+begin_src emacs-lisp (let* ((mafia-game (mafia :actors (mafia-initialize-actors 6))) (actors (slot-value mafia-game 'actors))) - (cons '(class id alive?) + (cons '(class id alive?) ;; add the header row (mapcar (lambda (a) (let ((class (eieio-object-class a))) - (list class (slot-value a 'id) - (when (eql class 'mafia-innocent) (slot-value a 'alive))))) + (with-slots (id alive) a + (list class id (when (eql class 'mafia-innocent) alive))))) actors))) #+end_src #+RESULTS: | class | id | alive? | | mafia-innocent | 1 | t | -| mafia-innocent | 2 | t | +| mafia-killer | 2 | nil | | mafia-innocent | 3 | t | | mafia-innocent | 4 | t | | mafia-innocent | 5 | t | -| mafia-killer | 6 | nil | +| mafia-innocent | 6 | t | ** Game loop The game loop will advance by a single tick where each actor /observes/ the others. -So... we need to define a game loop function, and a method for the actors to observe. - +So... we need to define a game loop function, and a method for the actors to #+name: game-loop #+begin_src emacs-lisp :results silent (defun mafia-play (players) |