From 450f4e8df494b9f2aeba5bc47d261d4547a962ab Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Thu, 24 Jul 2025 12:02:20 -0400 Subject: improve UnitAI abort error message --- go/game/ai.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/go/game/ai.go b/go/game/ai.go index abdebba4..d2caa008 100644 --- a/go/game/ai.go +++ b/go/game/ai.go @@ -22,6 +22,10 @@ type UnitAI struct { syncGameState *sync.WaitGroup } +func (ai *UnitAI) String() string { + return fmt.Sprintf("UnitAI(%s, %v)", getUnitAIDesc(ai.u), ai.u) +} + // NextAction returns the next Action from the AI and if there are more action to receive. func (ai *UnitAI) NextAction() (a Action, ok bool) { a, ok = <-ai.actions @@ -57,15 +61,19 @@ func (ai *UnitAI) Execute(f func(*UnitAI)) { } } +func getUnitAIDesc(u *Unit) (desc string) { + desc = u.Card().getAI() + if desc == "" { + desc = SuggestUnitAI(u) + } + return desc +} + func NewUnitAI(s *LocalState, u *Unit) *UnitAI { - aiDesc := u.Card().getAI() + aiDesc := getUnitAIDesc(u) if aiDesc == "" { - aiDesc = SuggestUnitAI(u) - if aiDesc == "" { - return nil - } + return nil } - return NewUnitAIFromDesc(s, u, aiDesc) } @@ -660,7 +668,7 @@ func (ai *SimpleAiControl) handlePriority() Action { continue } if a == nil && more { - log.Fatal(uAi, "returned a nil action") + log.Fatal(uAi, " returned a nil action") } return a } -- cgit v1.2.3