aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go/game/ai.go22
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
}