aboutsummaryrefslogtreecommitdiff
path: root/go/game/cardImplementations_test.go
blob: 1ad7e142567b70d72cd6a51944eb678e2fdf8f60 (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
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")
	}
}