diff options
| -rw-r--r-- | go/game/ai_test.go | 16 | ||||
| -rw-r--r-- | go/game/areaEffect_test.go | 2 | ||||
| -rw-r--r-- | go/game/artifact.go | 4 | ||||
| -rw-r--r-- | go/game/equipment.go | 10 | ||||
| -rw-r--r-- | go/game/player_test.go | 6 |
5 files changed, 27 insertions, 11 deletions
diff --git a/go/game/ai_test.go b/go/game/ai_test.go index 632c6991..528028f7 100644 --- a/go/game/ai_test.go +++ b/go/game/ai_test.go @@ -5,6 +5,8 @@ import ( "testing" ) +var player = NewMockPlayer() + func TestGenerateGraph(t *testing.T) { mapDef := `map: |1- HST @@ -18,8 +20,8 @@ symbols: ` r := strings.NewReader(mapDef) m, _ := readMap(r) - a := NewUnit(NewCard("base/archer"), m.TileAt(Position{0, 0}), nil) - f := NewUnit(NewCard("misc/farmer"), m.TileAt(Position{2, 2}), nil) + a := NewUnit(NewCard("base/archer"), m.TileAt(Position{0, 0}), player) + f := NewUnit(NewCard("misc/farmer"), m.TileAt(Position{2, 2}), player) graph := m.generateMapGraphFor(a) p, err := findPathTo(graph, a, Position{1, 1}) @@ -57,8 +59,8 @@ symbols: if m == nil || err != nil { t.Fatal("failed to parse map", m, err) } - s := NewUnit(NewCard("kraken/angry_squid"), m.TileAt(Position{5, 0}), nil) - f := NewUnit(NewCard("misc/farmer"), m.TileAt(Position{6, 5}), nil) + s := NewUnit(NewCard("kraken/angry_squid"), m.TileAt(Position{5, 0}), player) + f := NewUnit(NewCard("misc/farmer"), m.TileAt(Position{6, 5}), player) graph := m.generateMapGraphFor(s) @@ -182,19 +184,19 @@ symbols: ` r := strings.NewReader(mapDef) m, _ := readMap(r) - a := NewUnit(NewCard("base/archer"), m.TileAt(Position{0, 0}), nil) + a := NewUnit(NewCard("base/archer"), m.TileAt(Position{0, 0}), player) if SuggestUnitAI(a) != "aggressive" { t.Fatal("expected aggressive") } - f := NewUnit(NewCard("misc/farmer"), m.TileAt(Position{2, 2}), nil) + f := NewUnit(NewCard("misc/farmer"), m.TileAt(Position{1, 1}), player) exp := "target-oriented farm tile" is := SuggestUnitAI(f) if exp != is { t.Fatal(exp, " != ", is) } - tc := NewUnit(NewCard("base/tax_collector"), m.TileAt(Position{3, 3}), nil) + tc := NewUnit(NewCard("base/tax_collector"), m.TileAt(Position{2, 2}), player) if SuggestUnitAI(tc) != "shy" { t.Fatal("expected shy") } diff --git a/go/game/areaEffect_test.go b/go/game/areaEffect_test.go index 17688f1e..0da2c8ac 100644 --- a/go/game/areaEffect_test.go +++ b/go/game/areaEffect_test.go @@ -65,6 +65,6 @@ symbols: t.Fatalf("destroyed archer did not leave tile %v", t0_1) } - sword := newEquipmentFromPath("base/sword", t, p) + sword := newEquipmentFromPath("base/sword", t0_1, p) s.addPermanent(sword) } diff --git a/go/game/artifact.go b/go/game/artifact.go index 81692346..9bf653ef 100644 --- a/go/game/artifact.go +++ b/go/game/artifact.go @@ -17,7 +17,9 @@ func NewArtifactFromPath(cardPath string, tile *Tile, owner *Player) *Artifact { } func NewArtifact(card *Card, tile *Tile, owner *Player) *Artifact { - a := &Artifact{newPermanentBase(card, tile, owner), 0} + a := &Artifact{ + permanentBase: permanentBase{card: card, owner: owner, controller: owner}, + } effects := card.getEffects() for _, e := range effects { diff --git a/go/game/equipment.go b/go/game/equipment.go index 32bb358c..ce21750f 100644 --- a/go/game/equipment.go +++ b/go/game/equipment.go @@ -1,16 +1,20 @@ package game +import ( + "log" +) + type Equipment struct { Artifact Durability int } -func newEquipmentFromPath(cardPath string, containing interface{}, owner *Player) *Equipment { +func newEquipmentFromPath(cardPath string, containing any, owner *Player) *Equipment { card := NewCard(cardPath) return newEquipment(card, containing, owner) } -func newEquipment(card *Card, containing interface{}, owner *Player) *Equipment { +func newEquipment(card *Card, containing any, owner *Player) *Equipment { e := &Equipment{ *NewArtifact(card, nil, owner), card.Values["durability"].(int), @@ -22,6 +26,8 @@ func newEquipment(card *Card, containing interface{}, owner *Player) *Equipment e.tile = containing case *Unit: addPermanentToPile(containing, e) + default: + log.Panicf("unhandled containing type: %t\n", containing) } } diff --git a/go/game/player_test.go b/go/game/player_test.go new file mode 100644 index 00000000..418a4ee6 --- /dev/null +++ b/go/game/player_test.go @@ -0,0 +1,6 @@ +package game + +// NewMockPlayer returns an unusable zero-value Player +func NewMockPlayer() *Player { + return &Player{} +} |
