aboutsummaryrefslogtreecommitdiff
path: root/go/game/ai_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/game/ai_test.go')
-rw-r--r--go/game/ai_test.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/go/game/ai_test.go b/go/game/ai_test.go
new file mode 100644
index 00000000..5b68ae27
--- /dev/null
+++ b/go/game/ai_test.go
@@ -0,0 +1,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")
+ }
+}