From ed473052c558fbda6bb03d9083b425cb2e7a808f Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Tue, 22 Jul 2025 19:25:43 -0400 Subject: do not pass the map through the Attackable* function family --- go/game/ai.go | 2 +- go/game/unit.go | 13 +++++++------ go/game/unit_test.go | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/go/game/ai.go b/go/game/ai.go index b7d42b0e..7b20d187 100644 --- a/go/game/ai.go +++ b/go/game/ai.go @@ -445,7 +445,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() { if p == ai.u { inEnemyAttackRange = true break out diff --git a/go/game/unit.go b/go/game/unit.go index c7528224..1bf3afa1 100644 --- a/go/game/unit.go +++ b/go/game/unit.go @@ -112,12 +112,13 @@ func (u *Unit) MoveRangeTiles(m *Map) []*Tile { return tiles } -func (u *Unit) AttackableTiles(m *Map) []*Tile { +func (u *Unit) AttackableTiles() []*Tile { // Units not on the map can not attack if u.tile == nil { return nil } + m := u.controller.gameState.Map() tilesInRange := TilesInRange(m, u, u.Attack.MaxRange()) if u.Attack.MaxRange() == 1 { return tilesInRange @@ -134,9 +135,9 @@ func (u *Unit) AttackableTiles(m *Map) []*Tile { return aTiles } -func (u *Unit) AttackablePermanents(m *Map) []Permanent { +func (u *Unit) AttackablePermanents() []Permanent { permanents := []Permanent{} - for _, t := range u.AttackableTiles(m) { + for _, t := range u.AttackableTiles() { if t.Permanent != nil && t.Permanent.Attackable() { permanents = append(permanents, t.Permanent) } @@ -144,10 +145,10 @@ func (u *Unit) AttackablePermanents(m *Map) []Permanent { return permanents } -func (u *Unit) AttackableEnemyPermanents(m *Map) []Permanent { +func (u *Unit) AttackableEnemyPermanents() []Permanent { controller := u.Controller() permanents := []Permanent{} - for _, t := range u.AttackableTiles(m) { + for _, t := range u.AttackableTiles() { if t.Permanent != nil && t.Permanent.Attackable() && t.Permanent.Controller() != controller { @@ -182,7 +183,7 @@ func (u *Unit) AvailSlowActions() (actions []Action) { m := u.Controller().gameState.Map() if u.AvailAttackActions > 0 && !INVALID_ATTACK(u.Attack) && - len(u.AttackableEnemyPermanents(m)) > 0 { + len(u.AttackableEnemyPermanents()) > 0 { actions = append(actions, NewAttackAction(u)) } diff --git a/go/game/unit_test.go b/go/game/unit_test.go index e707c560..94fd3893 100644 --- a/go/game/unit_test.go +++ b/go/game/unit_test.go @@ -61,7 +61,7 @@ symbols: t.Fatalf("Piled archer is attackable") } - if len(a.AttackableTiles(s.Map())) != 0 { + if len(a.AttackableTiles()) != 0 { t.Fatalf("Piled archer has attackable tiles") } @@ -117,13 +117,13 @@ symbols: } } - aTiles := a.AttackableTiles(m) + aTiles := a.AttackableTiles() is := len(aTiles) if is != 6 { t.Fatal("6 attackable tiles expected not:", is) } - aPerms := a.AttackableEnemyPermanents(m) + aPerms := a.AttackableEnemyPermanents() is = len(aPerms) if is != 6 { t.Fatal("6 attackable permanents expected not:", is) -- cgit v1.2.3