diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-07-24 12:02:20 -0400 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-07-24 12:22:10 -0400 |
| commit | 450f4e8df494b9f2aeba5bc47d261d4547a962ab (patch) | |
| tree | 122b4ae5ca354409c46c0c90dd8e28de01cf88ca | |
| parent | 7503a591756081e06137db7707c690ffffb04553 (diff) | |
| download | muhqs-game-450f4e8df494b9f2aeba5bc47d261d4547a962ab.tar.gz muhqs-game-450f4e8df494b9f2aeba5bc47d261d4547a962ab.zip | |
improve UnitAI abort error message
| -rw-r--r-- | go/game/ai.go | 22 |
1 files 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 } |
