summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrant Shangreaux <grant@unabridgedsoftware.com>2022-01-22 21:01:05 -0600
committerGrant Shangreaux <grant@unabridgedsoftware.com>2022-01-22 21:01:05 -0600
commit1c57ce0d20eebbf2ace69bf59213857ca616ebf4 (patch)
tree9298090168e9cc57f429a65684dfb1e1755e369f
parentde237aee0efcf74a91f5faa4da44565a0b5e7f92 (diff)
Add: thinking and code sketches for observation
-rw-r--r--mafia.org63
1 files changed, 55 insertions, 8 deletions
diff --git a/mafia.org b/mafia.org
index 510c140..24c1d9e 100644
--- a/mafia.org
+++ b/mafia.org
@@ -25,7 +25,7 @@ the following source block represents the whole program from a high level:
<<top-level-mafia-methods>>
- <<actor-behavior-methods>>
+ ;; <<actor-behavior-methods>>
<<game-loop>>
#+end_src
@@ -97,13 +97,15 @@ use inheritance here to set apart the killer with its own ~:initform~.
#+begin_src emacs-lisp :results silent
(defclass mafia-actor ()
((id :initarg :id
- :type number))
+ :type number)
+ (being-watched? :initarg nil)
+ (current-target :initarg nil))
"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")
@@ -183,17 +185,62 @@ So... we need to define a game loop function, and a method for the actors to
:header-args: :noweb-ref actor-behavior-methods :noweb-sep "\n\n"
:END:
-This may be somewhat redundant, because the slot is meant to hold a boolean
-value anyway. However, if we added other "types" of actors, perhaps we'd
-specialize this method for them.
+*** Observation
+
+Each actor will have a ~current-target~, another actor they are observing.
+While they are observing, they'll notice who their target is observing.
+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.
+
+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
+the game. If the other two make eye contact, they will never want to
+observe the other player, because then they'll be killed. One of the two
+would /accuse/ and the other would /second/ and they win.
+
+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. ???
+
+#+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))
"Returns `t' if the actor is alive, otherwise `nil'"
(eql (slot-value obj 'status) 'alive))
#+end_src
-Then we want a method to make an actor die. For now, we'll just print some
+*** Dying innocents
+We need a method to make an actor die. For now, we'll just print some
message and update its state so that the ~alive~ slot is ~nil~. According
to the game rules, we should start some "timer" so that it will count down
its ~death-countown~, but I'm not quite prepared for that at this moment.