aboutsummaryrefslogtreecommitdiff
path: root/go/game/attack_test.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-08-02 14:47:01 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:57:33 +0200
commitc696829f9e37e9f3752fdb89ebaadd4b3b237bea (patch)
treea205a17da9618e04f61e44d49cb028ede23dd732 /go/game/attack_test.go
parentca083639a4b52215b39bb863031f71c0a8209ee9 (diff)
downloadmuhqs-game-c696829f9e37e9f3752fdb89ebaadd4b3b237bea.tar.gz
muhqs-game-c696829f9e37e9f3752fdb89ebaadd4b3b237bea.zip
add support for flexible attacks
Diffstat (limited to 'go/game/attack_test.go')
-rw-r--r--go/game/attack_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/go/game/attack_test.go b/go/game/attack_test.go
index 6327b8eb..a13b4795 100644
--- a/go/game/attack_test.go
+++ b/go/game/attack_test.go
@@ -50,3 +50,37 @@ func TestAttackString(t *testing.T) {
t.Fatal("unexpected attack string:", a.String())
}
}
+
+func TestAttackCopy(t *testing.T) {
+ aStr := "2 range 3"
+ a := parseAttack(aStr)
+ c := a.Copy()
+ c.Extend(1)
+ if a.MaxRange() != 3 {
+ t.Fatal("changed max range")
+ }
+ c.attacks[0] = 1
+ if a.attacks[0] != 2 {
+ t.Fatal("changed attack in range 0")
+ }
+}
+
+func TestPikeAttack(t *testing.T) {
+ a := parseAttack("1")
+ a.flexAttack = pikeAttack()
+ o := &Tile{Position: Position{0, 0}}
+ u := NewUnit(NewCard("base/cavalry"), o, NewMockPlayer())
+ enterTile(u, o)
+
+ tile := &Tile{Position: Position{1, 2}}
+ enterTile(NewUnitFromPath("base/cavalry", tile, NewMockPlayer()), tile)
+
+ // This test is crooked because the attack of the attacking unit is checked in flexAttack and not a.
+ d, ok := a.DamageForTile(u, tile)
+ if !ok {
+ t.Fatal("cavalry not in range for pike attack")
+ }
+ if d != u.Attack.DamageInRange(u.Attack.MaxRange()) {
+ t.Fatal("unexpected damage: amount", d)
+ }
+}