summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrant Shangreaux <grant@unabridgedsoftware.com>2022-01-24 10:04:29 -0600
committerGrant Shangreaux <grant@unabridgedsoftware.com>2022-01-24 10:04:29 -0600
commit089946168e646271e840b5e20d3b8ef9c97d0580 (patch)
tree297e7bff1fb6069e831dace385f541bd39a799f0
parent1c57ce0d20eebbf2ace69bf59213857ca616ebf4 (diff)
Add: WIP implementation of actor observation
Add notes alist slot to mafia-actor class
-rw-r--r--mafia.org62
1 files changed, 42 insertions, 20 deletions
diff --git a/mafia.org b/mafia.org
index 24c1d9e..f3ab461 100644
--- a/mafia.org
+++ b/mafia.org
@@ -96,16 +96,16 @@ use inheritance here to set apart the killer with its own ~:initform~.
#+name: actor-classes
#+begin_src emacs-lisp :results silent
(defclass mafia-actor ()
- ((id :initarg :id
- :type number)
- (being-watched? :initarg nil)
- (current-target :initarg nil))
+ ((id :initarg :id :type number)
+ (being-watched? :documentation "Returns true if this actor believes they're being watched.")
+ (current-target :documentation "Id of another actor being observed.")
+ (notes :initform '() :documentation "An alist containing pairs of (id . target-id)"))
"Base class for mafia actors.")
-
+
(defclass mafia-killer (mafia-actor)
()
"Actor subclass to represent the killer.")
-
+
(defclass mafia-innocent (mafia-actor)
((status :initform 'alive
:documentation "'alive, 'dying, or 'dead")
@@ -193,6 +193,37 @@ If two actors are observing each other, they have *eye-contact*. The killer
will wink if they believe they aren't ~being-watched?~ when eye contact
is being made.
+#+begin_src emacs-lisp
+ (cl-defgeneric mafia-observe (a b)
+ "Behavior for actor a observing actor b.")
+
+ (cl-defmethod mafia-observe ((actor mafia-actor) other)
+ "Base behavior for an actor which add a note about the current target
+ of `other' to the `actor's notes alist."
+ (with-slots (notes) actor
+ (with-slots (id current-target) other
+ (setf notes (cons `(,id . ,(slot-value current-target 'id)) notes)))))
+
+ (cl-defmethod mafia-observe ((killer mafia-killer) other)
+ "Specialized behavior for the `mafia-killer'."
+ (with-slots ((being-watched?)) killer
+ ;; (if being-watched?
+ ;; (mafia-maybe-refocus killer)
+ (if (mafia-eye-contact? killer other)
+ (print "the killer winks")
+ (print "the killer abides"))
+ ;; (mafia-wink other)
+ (cl-call-next-method killer other))))
+
+ (cl-defmethod mafia-eye-contact? (a b)
+ "Given two `mafia-actor's, returns t if they are eachother's current target."
+ (and (equal (slot-value a 'current-target) b)
+ (equal (slot-value b 'current-target) a)))
+#+end_src
+
+#+RESULTS:
+: mafia-eye-contact\?
+
Imagining "optimal" play if there are only 3 actors. The game begins and
each actor chooses a target. If the killer makes eye contact with anyone,
they'll wink, no matter if they're being observed or not, since they win
@@ -204,34 +235,25 @@ Add in a 4th actor, and then its trickier. The killer would like to wink
when they are sure they aren't being watched and then immediately try for
eye contact with another actor. The other actors may want to maintain
eye contact as long as they feel the actor they are observing is being
-watched by someone else. ???
+watched by someone else. ???
#+begin_src emacs-lisp
- (cl-defgeneric mafia-observe (a b)
- "Behavior for actor a observing actor b.")
-
- (cl-defmethod mafia-observe ((killer mafia-killer) other)
- (with-slots ((being-watched?) killer)
- (if being-watched?
- (mafia-maybe-refocus killer)
- (mafia-wink other))))
-
+
(cl-defgeneric mafia-maybe-refocus (actor)
"Actor decides to maintain observation target or pick another.")
-
+
(cl-defmethod mafia-maybe-refocus ((actor mafia-actor) other-actors)
(when (mafia-refocus? actor)
(mafia-refocus actor other-actors)))
-
+
(cl-defmethod mafia-refocus? ((actor mafia-killer))
(slot-value actor 'being-watched?))
-
+
(cl-defmethod mafia-refocus ((actor) other-actors)
(with-slots ((current-target) actor)
(setf current-target (seq-random-elt other-actors))))
#+end_src
-
*** Helper method to tell if an actor is alive
#+begin_src emacs-lisp
(cl-defmethod mafia-alive-p ((obj mafia-innocent))