fix: eating stew

This commit is contained in:
jonas committed 2026-09-03 23:44:38 +02:00
1 parent aab128b55c
commit 0c4ca0e4f9
2 files changed
+18 -1

No files matched your search

@@ -22,7 +22,7 @@ func main() {
elsa := westworldwithmessaging.NewElsa(2) elsa := westworldwithmessaging.NewElsa(2)
const ( const (
numUpdateSteps = 40 numUpdateSteps = 100
tickDelay = 100 * time.Millisecond tickDelay = 100 * time.Millisecond
) )
@@ -55,9 +55,26 @@ func (s *wifesGlobalState) Execute(e *Elsa) {
// specifically because she should react to it "when in any state," // specifically because she should react to it "when in any state,"
// same reasoning as why the bathroom-call check above lives in the // same reasoning as why the bathroom-call check above lives in the
// global state rather than in DoHousework. // global state rather than in DoHousework.
//
// One guard we added that the book's snippet didn't show: if Bob
// comes home again while a stew is already in the oven (his fatigue
// or thirst can send him home more than once before her 1.5-second
// cooking timer fires), this used to unconditionally call
// ChangeState(CookStew()) even though she was already IN CookStew.
// That triggered a pointless Exit-then-Enter round trip on the same
// state - CookStew.Exit fired (printing "Puttin' the stew on the
// table" while the stew was still cooking!) and then Enter's
// "!e.Cooking()" check correctly skipped starting a second stew, so
// nothing useful happened, just a confusing extra print. Checking
// Cooking() first avoids the whole misfire.
func (s *wifesGlobalState) OnMessage(e *Elsa, msg Telegram) bool { func (s *wifesGlobalState) OnMessage(e *Elsa, msg Telegram) bool {
switch MessageType(msg.Msg) { switch MessageType(msg.Msg) {
case MsgHiHoneyImHome: case MsgHiHoneyImHome:
if e.Cooking() {
// already got dinner covered - nothing new to do
return true
}
fmt.Printf("\nMessage handled by %s at time: %.5f", GetNameOfEntity(e.ID()), Clock.GetCurrentTime()) fmt.Printf("\nMessage handled by %s at time: %.5f", GetNameOfEntity(e.ID()), Clock.GetCurrentTime())
fmt.Printf("\n%s: Hi honey. Let me make you some of mah fine country stew", GetNameOfEntity(e.ID())) fmt.Printf("\n%s: Hi honey. Let me make you some of mah fine country stew", GetNameOfEntity(e.ID()))
e.FSM().ChangeState(CookStew()) e.FSM().ChangeState(CookStew())