From 6cac8e514d90e3bd8f547952e841f05cb6d09a2e Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 21 Jul 2025 08:33:01 -0400 Subject: detect end of unit AI actions and tap the unit --- go/game/ai.go | 16 +++++++++++++--- go/game/unit.go | 5 +++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/go/game/ai.go b/go/game/ai.go index a60353db..35fa19cc 100644 --- a/go/game/ai.go +++ b/go/game/ai.go @@ -22,10 +22,13 @@ type UnitAI struct { syncGameState *sync.WaitGroup } -func (ai *UnitAI) NextAction() Action { - return <-ai.actions +// 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 + return } +// PostAndContinue publishes the action and reports if the AI should continue executing. func (ai *UnitAI) PostAndContinue(a Action) bool { if a == nil { return true @@ -35,6 +38,7 @@ func (ai *UnitAI) PostAndContinue(a Action) bool { return ai.awaitGameStateSync() } +// awaitGameStateSync waits until a new action is needed and reports if the unit is destroyed. func (ai *UnitAI) awaitGameStateSync() bool { ai.syncGameState.Wait() ai.syncGameState.Add(1) @@ -611,7 +615,13 @@ func (ai *SimpleAiControl) handlePriority() Action { ai.uAis[u] = uAi } uAi.promptAction() - return uAi.NextAction() + a, more := uAi.NextAction() + if !more { + // Consume all available actions to not consider the unit this term again. + u.tap() + continue + } + return a } } case Phases.BuyPhase: diff --git a/go/game/unit.go b/go/game/unit.go index fd08b481..a096c0f2 100644 --- a/go/game/unit.go +++ b/go/game/unit.go @@ -154,6 +154,11 @@ func (u *Unit) HasFullAction() bool { return len(u.FullActions) > 0 } +func (u *Unit) tap() { + u.AvailMoveActions = 0 + u.AvailAttackActions = 0 +} + func (u *Unit) AvailSlowActions() (actions []Action) { if u.AvailMoveActions > 0 && u.Movement != INVALID_MOVEMENT() { actions = append(actions, NewMoveAction(u)) -- cgit v1.2.3