summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrant Shangreaux <grant@unabridgedsoftware.com>2022-01-30 20:54:25 -0600
committerGrant Shangreaux <grant@unabridgedsoftware.com>2022-01-30 20:54:25 -0600
commit41122fa276762ea02838cf575c31fc21f7d84729 (patch)
treeda4d025f82f66b0eec5b9a60044eea19ddc049ab
parentbd53520fb30fdcd366303fdd1032be9ebb255817 (diff)
Clean: methods -> defuns and renaming
-rw-r--r--mafia.org27
1 files changed, 18 insertions, 9 deletions
diff --git a/mafia.org b/mafia.org
index dfb3187..06b7733 100644
--- a/mafia.org
+++ b/mafia.org
@@ -23,7 +23,7 @@ the following source block represents the whole program from a high level:
<<initialization-helpers>>
- <<top-level-mafia-methods>>
+ <<top-level-game-functions>>
<<actor-behavior-methods>>
@@ -75,6 +75,7 @@ other actor reveals whether or not they are the killer. (Q: what makes the kille
join the consensus against themself?) If they are the killer, the other actors
win. If there's only 2 players left, the killer wins.
+*** Game class ~mafia~
using EIEIO, lets define a class ~mafia~ to represent the whole game state.
#+name: mafia-class
@@ -161,10 +162,11 @@ Lets initialize a game with 6 actors and inspect it to see what to expect.
| mafia-innocent | 5 | alive |
| mafia-killer | 6 | nil |
-** Game Loop
+** Basic 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
+
#+name: game-loop
#+begin_src emacs-lisp :results silent
(defun mafia-play (players)
@@ -176,19 +178,25 @@ So... we need to define a game loop function, and a method for the actors to
(message "Game over!")))
#+end_src
-#+name: top-level-mafia-methods
+** Top level game functions
+
+Now that i think of it, using functions here would be simpler. Its likely faster,
+and is definitely in Common Lisp. Unless we want to dispatch or use method chains,
+there is not reason to define methods a la Ruby.
+
+#+name: top-level-mafia-functions
#+begin_src emacs-lisp :results silent
- (cl-defmethod mafia-living-innocents ((obj mafia))
+ (defun mafia-living-innocents (game)
"Returns the living innocents from a mafia game."
- (cl-remove-if-not #'mafia-alive-p (mafia-innocents obj)))
+ (cl-remove-if-not #'mafia-alive-p (mafia-innocents game)))
- (cl-defmethod mafia-update ((obj mafia))
+ (defun mafia-update (game)
"Performs the update logic for the mafia game instance."
- (mafia-innocent-die (cl-first (mafia-living-innocents obj))))
+ (mafia-innocent-die (cl-first (mafia-living-innocents game))))
- (cl-defmethod mafia-innocents ((obj mafia))
+ (defun mafia-innocents (game)
"Returns the list of innocents from a mafia game."
- (cl-remove-if #'mafia-killer-p (slot-value obj 'actors)))
+ (cl-remove-if #'mafia-killer-p (slot-value game 'actors)))
#+end_src
** Actor Behavior
@@ -383,5 +391,6 @@ its ~death-countown~, but I'm not quite prepared for that at this moment.
(setf status 'dead)))
#+end_src
+
* english villiage simulator
https://archaeology.co.uk/articles/specials/timeline/the-origins-of-the-english-village.htm