diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2024-12-27 12:40:19 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-01-27 16:43:58 +0100 |
| commit | 4e2ab55d345fd5e5c5d2d5bc56948611b15564d5 (patch) | |
| tree | c6998ac54687c442ad0baa541edd0fbf917b1308 /go/game/ai.go | |
| parent | 5aa8e7ddbc41aed55e7918e6afaec0b5c07fa510 (diff) | |
| download | muhqs-game-4e2ab55d345fd5e5c5d2d5bc56948611b15564d5.tar.gz muhqs-game-4e2ab55d345fd5e5c5d2d5bc56948611b15564d5.zip | |
introduce game.State interface abstraction
This allows to not use the internal game state directly from client
code.
Diffstat (limited to 'go/game/ai.go')
| -rw-r--r-- | go/game/ai.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/go/game/ai.go b/go/game/ai.go index 94a9f7ec..84b5973e 100644 --- a/go/game/ai.go +++ b/go/game/ai.go @@ -12,7 +12,7 @@ import ( ) type UnitAI struct { - s *State + s *LocalState u *Unit actions chan Action target *Target @@ -50,7 +50,7 @@ func (ai *UnitAI) Execute(f func(*UnitAI)) { } } -func NewUnitAI(s *State, u *Unit) *UnitAI { +func NewUnitAI(s *LocalState, u *Unit) *UnitAI { aiDesc := u.Card().getAI() if aiDesc == "" { return nil @@ -215,13 +215,13 @@ func moveTowardsNearestEnemyUnit(ai *UnitAI) Action { return nil } - graph := ai.s.Map.generateMapGraphFor(ai.u) + graph := ai.s.Map().generateMapGraphFor(ai.u) enemyUnits := ai.s.EnemyUnits(ai.u.Controller()) if len(enemyUnits) == 0 { return nil } - paths := findPathsToUnits(graph, ai.s.Map, ai.u, enemyUnits) + paths := findPathsToUnits(graph, ai.s.Map(), ai.u, enemyUnits) nearest := 0 for i, p := range paths { if p == nil { @@ -251,7 +251,7 @@ func moveTowardsNearestEnemyUnit(ai *UnitAI) Action { } a := NewMoveAction(ai.u) - _ = a.Target().AddSelection(ai.s.Map.TileAt(target)) + _ = a.Target().AddSelection(ai.s.Map().TileAt(target)) return a } @@ -327,7 +327,7 @@ func ShyAI(ai *UnitAI) { inEnemyAttackRange := false out: for _, enemyUnit := range ai.s.EnemyUnits(ai.u.Controller()) { - for _, p := range enemyUnit.AttackablePermanents(ai.s.Map) { + for _, p := range enemyUnit.AttackablePermanents(ai.s.Map()) { if p == ai.u { inEnemyAttackRange = true break out |
