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
|
package game
import (
"testing"
"golang.org/x/exp/slices"
)
func TestKingGame(t *testing.T) {
s := NewLocalState()
s.SetMap(newEmpty2x2Map())
s._map.WinCondition = KingGame
p := s.AddNewPlayer("p", NewDeck())
k1 := s.addNewUnit(NewCard("misc/king"), Position{0, 0}, p)
o := s.AddNewPlayer("o", NewDeck())
k2 := s.addNewUnit(NewCard("misc/king"), Position{1, 1}, o)
w := s._map.WinCondition(s)
if len(w) != 0 {
t.Fatal("winners declared with two kings")
}
s.destroyPermanent(k2)
w = s._map.WinCondition(s)
if len(w) != 1 {
t.Fatal("winner not declared", w)
}
if w[0] != p {
t.Fatal("p is not the winner", w)
}
s.destroyPermanent(k1)
w = s._map.WinCondition(s)
if len(w) != 2 {
t.Fatal("winners not declared", w)
}
if !slices.Contains(w, p) || !slices.Contains(w, o) {
t.Fatal("p or o is not a winner", w)
}
}
|