1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
package game
import (
"log"
"strings"
"testing"
"muhq.space/muhqs-game/go/utils"
)
func TestPioneerFullAction(t *testing.T) {
mapDef := `map: |1-
HST
H H
FW
symbols:
T: tower
H: house
F: farm
S: street
W: deep water
`
s := NewLocalState()
m, _ := readMap(strings.NewReader(mapDef))
s.SetMap(m)
player := s.AddNewPlayer("p", NewDeck())
p := s.addNewUnit(NewCard("base/pioneer"), Position{1, 1}, player)
sword := s.addNewEquipment(NewCard("base/sword"), Position{0, 1}, player)
palisade := s.addNewArtifact(NewCard("base/palisade"), Position{0, 0}, player)
a := p.FullActions[0]
opts := a.Target().Options()
if len(opts) != 11 {
log.Printf("%q\n", opts)
t.Fatal("expexted 11 targets to neutralize")
}
if !utils.InterfaceSliceContains(opts, sword) {
t.Fatal("sword is missing")
}
if !utils.InterfaceSliceContains(opts, palisade) {
t.Fatal("palisade is missing")
}
_ = a.Target().AddSelection(m.TileAt(Position{0, 1}))
s.ResolveAction(a)
if m.TileAt(Position{0, 1}).Type != TileTypes.Neutral {
t.Fatal("tile not neutralized")
}
a = p.FullActions[0]
if len(a.Target().Selection()) != 0 {
t.Fatal("full action still has target selection")
}
_ = a.Target().AddSelection(palisade)
s.ResolveAction(a)
if m.TileAt(Position{0, 0}).Permanent != nil {
t.Fatal("palisade not destroyed")
}
}
func TestPikemanRange(t *testing.T) {
mapDef := `map: |1-
SSS
SSS
SHS
symbols:
S: street
H: house
`
s := NewLocalState()
m, _ := readMap(strings.NewReader(mapDef))
s.SetMap(m)
player := s.AddNewPlayer("p", NewDeck())
opo := s.AddNewPlayer("o", NewDeck())
p := s.addNewUnit(NewCard("base/pikeman"), Position{0, 0}, player)
c := s.addNewUnit(NewCard("base/cavalry"), Position{0, 2}, opo)
prot := s.addNewUnit(NewCard("base/cavalry_archer"), Position{1, 2}, opo)
ca := s.addNewUnit(NewCard("base/cavalry_archer"), Position{2, 1}, opo)
k := s.addNewUnit(NewCard("base/knight"), Position{2, 0}, opo)
attackable := utils.TypedSliceToInterfaceSlice(p.AttackableEnemyPermanents())
if !utils.InterfaceSliceContains(attackable, c) {
t.Fatal("cavalry not attackable")
}
if !utils.InterfaceSliceContains(attackable, ca) {
t.Fatal("cavalry archer not attackable")
}
if utils.InterfaceSliceContains(attackable, k) {
t.Fatal("knight is attackable")
}
if utils.InterfaceSliceContains(attackable, prot) {
t.Fatal("cavalry is protected")
}
a := NewAttackAction(p)
err := a.Target().AddSelection(c)
if err != nil {
t.Fatal("invalid target:", err)
}
s.ResolveAction(a)
if !c.IsDestroyed() {
t.Fatal("cavalry not destroyed")
}
a.Target().ClearSelection()
err = a.Target().AddSelection(ca)
if err != nil {
t.Fatal("invalid target:", err)
}
s.ResolveAction(a)
if !c.IsDestroyed() {
t.Fatal("cavalry archer not destroyed")
}
if p.Damage() != 1 {
t.Fatal("pikeman not damaged")
}
a.Target().ClearSelection()
err = a.Target().AddSelection(k)
if err == nil {
t.Fatal("unexpected valid target")
}
}
|