aboutsummaryrefslogtreecommitdiff
path: root/go/game/targets_test.go
blob: 9285bb134d9237da126c8ee3dec2dabee132efd5 (plain)
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package game

import (
	"strings"
	"testing"
)

func TestTileTargets(t *testing.T) {
	mapDef := `map: |1-
 HSTS
 HSFS
 TSWS

symbols:
  T: tower
  H: house
  F: farm
  S: street
  W: deep water
`
	s := NewLocalState()
	r := strings.NewReader(mapDef)
	m, _ := readMap(r)
	s.SetMap(m)

	p := s.AddNewPlayer("player", NewDeck())
	u := s.addNewUnit(NewCard("base/archer"), Position{1, 1}, p)
	s.addNewUnit(NewCard("base/cavalry"), Position{1, 2}, p)

	a := newFullAction(u,
		func(Action) ActionResolveFunc { var f ActionResolveFunc; return f },
		"mock full action")

	tDesc := newTargetDesc("tile")
	trgt := newTarget(s, tDesc, a)
	opts := trgt.Options()
	if len(opts) != 12 {
		t.Fatal("expexted 12 candidates not:", len(opts))
	}

	tDesc = newTargetDesc("water tile")
	trgt = newTarget(s, tDesc, a)
	opts = trgt.Options()
	if len(opts) != 1 {
		t.Fatal("expected 1 water candidates not:", len(opts))
	}

	tDesc = newTargetDesc("free tile")
	trgt = newTarget(s, tDesc, a)
	opts = trgt.Options()
	if len(opts) != 10 {
		t.Fatal("expected 10 free candidates not:", len(opts))
	}

	tDesc = newTargetDesc("available tile")
	trgt = newTarget(s, tDesc, a)
	opts = trgt.Options()
	if len(opts) != 9 {
		t.Fatal("expected 9 available candidates not:", len(opts))
	}

	tDesc = newTargetDesc("adjacent tile")
	trgt = newTarget(s, tDesc, a)
	opts = trgt.Options()
	if len(opts) != 9 {
		t.Fatal("expected 9 available candidates not:", len(opts))
	}

	tDesc = newTargetDesc("adjacent available tile")
	trgt = newTarget(s, tDesc, a)
	opts = trgt.Options()
	if len(opts) != 6 {
		t.Fatal("expected 6 available candidates not:", len(opts))
	}
}

func TestFlexAttackTargets(t *testing.T) {
	mapDef := `map: |1-
 HSTS
 HSFS
 TSWS

symbols:
  T: tower
  H: house
  F: farm
  S: street
  W: deep water
`
	s := NewLocalState()
	r := strings.NewReader(mapDef)
	m, _ := readMap(r)
	s.SetMap(m)

	p := s.AddNewPlayer("player", NewDeck())
	o := s.AddNewPlayer("oponent", NewDeck())

	u := s.addNewUnit(NewCard("base/pikeman"), Position{1, 1}, p)
	s.addNewUnit(NewCard("base/pikeman"), Position{0, 0}, o)
	s.addNewUnit(NewCard("base/pikeman"), Position{3, 1}, o)
	s.addNewUnit(NewCard("base/cavalry"), Position{3, 2}, o)

	a := NewAttackAction(u)
	opts := a.Target().Options()
	if len(opts) != 2 {
		t.Fatal("expected 2 attackable options")
	}

}

func TestDisjunction(t *testing.T) {
	mapDef := `map: |1-
 HST
 HSF
 TSW
symbols:
  T: tower
  H: house
  F: farm
  S: street
  W: deep water
`
	s := NewLocalState()
	m, _ := readMap(strings.NewReader(mapDef))
	s.SetMap(m)

	p := s.AddNewPlayer("player", NewDeck())

	pioneer := NewUnit(NewCard("base/pioneer"), s.Map().TileAt(Position{1, 1}), p)
	s.addPermanent(pioneer)

	sword := newEquipmentFromPath("base/sword", s.Map().TileAt(Position{0, 1}), p)
	s.addPermanent(sword)

	fa := pioneer.FullActions[0]
	targets := fa.Targets()
	if err := targets.AddSelection(s.Map().TileAt(Position{1, 1})); err != nil {
		t.Fatalf("TileAt(1,1) not a valid target for %v", fa)
	}

	if err := targets.CheckTargets(s); err != nil {
		t.Fatalf("TileAt(1,1) not a valid target for %v", fa)
	}

	targets.ClearSelections()

	if err := targets.AddSelection(sword); err != nil {
		t.Fatalf("%v not a valid target for %v", sword, fa)
	}

	if err := targets.CheckTargets(s); err != nil {
		t.Fatalf("%v not a valid target for %v", sword, fa)
	}
}