feat: add Chapter 2 gold miner FSM example in Go
Port the finite state machine from "Programming Game AI by Example" chapter 2: BaseGameEntity, a generic State[T]/StateMachine[T] pair (Go generics standing in for the book's C++ templates), and a Miner that cycles through digging, banking, sleeping, and drinking states. VisitBankAndDepositGold, GoHomeAndSleepTilRested, and QuenchThirst are original implementations based on the book's written behavior description, since their C++ source wasn't available. Includes a runnable demo in main.go.
This commit is contained in:
1 parent
f09fa6d548
commit
2764849943
11 files changed
+787
No files matched your search
@@ -0,0 +1,22 @@
|
||||
// Command westworld runs a tiny demo of the finite state machine
|
||||
// built in the westworld package: it creates one miner and lets him
|
||||
// tick forward on his own, watching his state machine drive him
|
||||
// around the loop (sleep -> dig -> bank/saloon -> sleep, ...).
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.jjstudio.me/jonas/Programming-Game-AI-by-Example-Go/chapter-2-state-driven-agent-design/westworld"
|
||||
)
|
||||
|
||||
func main() {
|
||||
bob := westworld.NewMiner(1)
|
||||
|
||||
const numUpdateSteps = 30
|
||||
for range numUpdateSteps {
|
||||
bob.Update()
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
}
|
||||
Reference in new issue
Block a user