38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
// Command westworldwithmessaging runs the full messaging demo: Miner
|
|
// Bob and Elsa tick forward together, and each iteration also flushes
|
|
// any delayed telegrams that have come due (Dispatch.DispatchDelayedMessages).
|
|
//
|
|
// Our Clock measures real wall-clock time, same as the book's, and
|
|
// Elsa's CookStew reminder uses a real 1.5 second delay - so this
|
|
// loop sleeps a little each tick and runs for several seconds of
|
|
// real time, giving that delayed message an actual chance to fire
|
|
// before the program ends. A tight, sleep-free loop would finish in
|
|
// microseconds and the stew would never get made.
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"git.jjstudio.me/jonas/Programming-Game-AI-by-Example-Go/chapter-2-state-driven-agent-design/westworldwithmessaging"
|
|
)
|
|
|
|
func main() {
|
|
bob := westworldwithmessaging.NewMiner(1)
|
|
elsa := westworldwithmessaging.NewElsa(2)
|
|
|
|
const (
|
|
numUpdateSteps = 100
|
|
tickDelay = 100 * time.Millisecond
|
|
)
|
|
|
|
for range numUpdateSteps {
|
|
westworldwithmessaging.Dispatch.DispatchDelayedMessages()
|
|
bob.Update()
|
|
elsa.Update()
|
|
time.Sleep(tickDelay)
|
|
}
|
|
|
|
fmt.Println()
|
|
}
|