Files
Programming-Game-AI-by-Exam…/chapter-2-state-driven-agent-design/westworld/names.go
T
jonas 2764849943 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.
2026-09-03 11:36:05 +02:00

21 lines
615 B
Go

package westworld
import "fmt"
// entityNames is a temporary stand-in for the book's real name
// lookup table. We still haven't been shown that table, so this is
// just a small map we're filling in by hand as we meet entities -
// right now that's only the miner from main.go, whose ID is 1.
var entityNames = map[int]string{
1: "Miner Bob",
}
// GetNameOfEntity looks up a friendly name for a given entity ID.
// Anything not in entityNames falls back to printing the raw ID.
func GetNameOfEntity(id int) string {
if name, ok := entityNames[id]; ok {
return name
}
return fmt.Sprintf("Entity %d", id)
}