aboutsummaryrefslogtreecommitdiff
path: root/go/game/ai_test.go
blob: 5b68ae2750db4379f900e5c4e0fc5b7073febc26 (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
package game

import (
	"strings"
	"testing"
)

func TestGenerateGraph(t *testing.T) {
	mapDef := `map: |1-
 HST
 HSF
 TST
symbols:
  T: tower
  H: house
  F: farm
  S: street
`
	r := strings.NewReader(mapDef)
	m, _ := readMap(r)
	a := NewUnit(NewCard("base/archer"), m.TileAt(Position{0, 0}), nil)
	f := NewUnit(NewCard("misc/farmer"), m.TileAt(Position{2, 2}), nil)

	graph := m.generateMapGraphFor(a)
	p, err := findPathTo(graph, a, Position{1, 1})
	if err != nil {
		t.Fatal(err)
	}

	if p.Distance != 3 {
		t.Fatalf("Wrong distance %d", p.Distance)
	}

	paths := findPathsToUnits(graph, m, a, []*Unit{f})
	if paths[0] == nil {
		t.Fatal("No path found")
	}

	if paths[0].Distance != 3 {
		t.Fatalf("Wrong distance %d", p.Distance)
	}
}

func TestAngrySquidDiagonal(t *testing.T) {
	mapDef := `map: |1-
 WWWWWWW
 W     W
 WW   WW
 WWWWWWW
 WWWWWWW
 W     W
symbols:
  W: deep water
`
	r := strings.NewReader(mapDef)
	m, _ := readMap(r)
	s := NewUnit(NewCard("kraken/angry_squid"), m.TileAt(Position{5, 0}), nil)
	f := NewUnit(NewCard("misc/farmer"), m.TileAt(Position{6, 5}), nil)

	graph := m.generateMapGraphFor(s)

	paths := findPathsToUnits(graph, m, s, []*Unit{f})
	if paths[0] == nil {
		t.Fatal("No path found")
	}
}