aboutsummaryrefslogtreecommitdiff
path: root/go/game/state_test.go
blob: c6b0004e1346d99c6de68ebdcbe3e3832c1c4ebb (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
package game

import (
	"strings"
	"testing"
)

func (s *LocalState) addMockPlayers() (p *Player, o *Player) {
	p = s.AddNewPlayer("p", NewDeck())
	p.Ctrl = newMockPlayerControl(p)

	o = s.AddNewPlayer("o", NewDeck())
	o.Ctrl = newMockPlayerControl(o)
	return
}

// newMockState creates a new LocalState with an empty 2x2 map and two players.
// The players "p" and "o" are initialized with mock player controls.
func newMockState() (*LocalState, *Map, *Player, *Player) {
	s := NewLocalState()
	m := newEmpty2x2Map()
	s.SetMap(m)
	p, o := s.addMockPlayers()
	return s, m, p, o
}

func newMockStateFromDef(mapDef string) (*LocalState, *Map, *Player, *Player) {
	s := NewLocalState()
	m, _ := readMap(strings.NewReader(mapDef))
	s.SetMap(m)
	p, o := s.addMockPlayers()
	return s, m, p, o
}

func TestDeclareActions(t *testing.T) {
	s, m, p, o := newMockState()
	p.Store.AddCard(NewCard("base/sword"))

	a := s.addNewUnit(NewCard("base/archer"), Position{0, 0}, p)
	k := s.addNewUnit(NewCard("base/knight"), Position{1, 1}, o)

	sa := NewAttackAction(a)
	sa.Target().AddSelection(k)
	s.declareAction(sa)
	if !s.stack.IsEmpty() {
		t.Fatal("declared attack action during upkeep")
	}

	ma := NewMoveAction(a)
	ma.Target().AddSelection(m.TileAt(Position{1, 0}))
	s.declareAction(ma)
	if !s.stack.IsEmpty() {
		t.Fatal("declared move action during upkeep")
	}

	ba := newBuyAction(p)
	ba.Target().AddSelection(p.Store.Cards()[0])
	s.declareAction(ba)
	if !s.stack.IsEmpty() {
		t.Fatal("declared buy action during upkeep")
	}

	s.activePhase = Phases.ActionPhase
	s.declareAction(sa)
	if s.stack.IsEmpty() {
		t.Fatal("attack action not declared")
	}

	s.declareAction(ma)
	if len(s.stack.Actions) == 2 {
		t.Fatal("declared move action with non empty stack")
	}
}