diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-07-21 08:33:01 -0400 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-07-22 12:54:28 -0400 |
| commit | 6cac8e514d90e3bd8f547952e841f05cb6d09a2e (patch) | |
| tree | 3010e9df91f3d09d197fac77b37f140f2e984e48 /go | |
| parent | 23f7a82322eb36433fee1fabeef538aa2d9428ac (diff) | |
| download | muhqs-game-6cac8e514d90e3bd8f547952e841f05cb6d09a2e.tar.gz muhqs-game-6cac8e514d90e3bd8f547952e841f05cb6d09a2e.zip | |
detect end of unit AI actions and tap the unit
Diffstat (limited to 'go')
| -rw-r--r-- | go/game/ai.go | 16 | ||||
| -rw-r--r-- | 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)) |
