diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-02-01 18:46:32 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-01-27 16:43:45 +0100 |
| commit | 21a87ffccae9950580a240180fd3703768ef450e (patch) | |
| tree | 1cb83289216bd1e213d417812b4e09001ca89c09 /go/game/ai.go | |
| parent | 3fd15c9b83fff074b588ff9688f9e49aab38cd32 (diff) | |
| download | muhqs-game-21a87ffccae9950580a240180fd3703768ef450e.tar.gz muhqs-game-21a87ffccae9950580a240180fd3703768ef450e.zip | |
intermediate commit
Diffstat (limited to 'go/game/ai.go')
| -rw-r--r-- | go/game/ai.go | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/go/game/ai.go b/go/game/ai.go index 01820a19..0adce722 100644 --- a/go/game/ai.go +++ b/go/game/ai.go @@ -138,17 +138,18 @@ func moveToRandomTile(ai *UnitAI) Action { return nil } - moveTargets := ai.u.MoveRangeTiles(ai.s.Map) - if len(moveTargets) == 0 { + a := NewMoveAction(ai.u) + options := a.Targets().NextOptions() + if len(options) == 0 { return nil } idx := 0 - if len(moveTargets) > 1 { - idx = ai.s.Rand.Intn(len(moveTargets) - 1) + if len(options) > 1 { + idx = ai.s.Rand.Intn(len(options) - 1) } - moveTarget := moveTargets[idx] - a := NewMoveActionPrototype(ai.u).Specialize(ai.s, moveTarget) + a.Targets().AddTarget(options[idx]) + return a } @@ -191,22 +192,28 @@ func moveTowardsNearestEnemyUnit(ai *UnitAI) Action { break } } - a := NewMoveActionPrototype(ai.u).Specialize(ai.s, ai.s.Map.TileAt(target)) + + a := NewMoveAction(ai.u) + a.Targets().AddTarget(ai.s.Map.TileAt(target)) return a } func attackAttackableEnemyPerm(ai *UnitAI) Action { - attackablePerms := ai.u.AttackableEnemyPermanents(ai.s.Map) - if ai.u.AvailAttackActions == 0 || len(attackablePerms) == 0 { + if ai.u.AvailAttackActions == 0 { + return nil + } + + a := NewAttackAction(ai.u) + options := a.Targets().NextOptions() + if len(options) == 0 { return nil } idx := 0 - if len(attackablePerms) > 1 { - idx = ai.s.Rand.Intn(len(attackablePerms) - 1) + if len(options) > 1 { + idx = ai.s.Rand.Intn(len(options) - 1) } - attackablePerm := attackablePerms[idx] - a := NewAttackActionPrototype(ai.u).Specialize(ai.s, attackablePerm) + a.Targets().AddTarget(options[idx]) return a } @@ -263,12 +270,18 @@ out: } } if !inEnemyAttackRange && ai.u.HasFullAction() { - fullActions := ai.u.Card().Impl.fullActionPrototypes(ai.u) + fullActions := ai.u.Card().Impl.fullActions(ai.u) idx := 0 if len(fullActions) > 1 { idx = ai.s.Rand.Intn(len(fullActions) - 1) } - a := fullActions[idx].Specialize(ai.s, ai.u) + + a := fullActions[idx] + options := a.Targets().NextOptions() + if len(options) > 1 { + idx = ai.s.Rand.Intn(len(options) - 1) + } + a.Targets().AddTarget(options[idx]) ai.actions <- a } |
