diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-07-21 08:34:17 -0400 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:57:26 +0200 |
| commit | 283f53e3e381fad773457a54bc20bf7f61db2c6e (patch) | |
| tree | 590c190df1d049e1cff5b2207fac601d7a6a5c17 | |
| parent | bcb3394dbcba288fa18b85c5dbc01da2ed9d72af (diff) | |
| download | muhqs-game-283f53e3e381fad773457a54bc20bf7f61db2c6e.tar.gz muhqs-game-283f53e3e381fad773457a54bc20bf7f61db2c6e.zip | |
add more AI tests
| -rw-r--r-- | go/game/ai_test.go | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/go/game/ai_test.go b/go/game/ai_test.go index 528028f7..854f38dd 100644 --- a/go/game/ai_test.go +++ b/go/game/ai_test.go @@ -196,8 +196,79 @@ symbols: t.Fatal(exp, " != ", is) } + k := NewUnit(NewCard("misc/king"), m.TileAt(Position{0, 1}), player) + if SuggestUnitAI(k) != "shy" { + t.Fatal("expected shy") + } + tc := NewUnit(NewCard("base/tax_collector"), m.TileAt(Position{2, 2}), player) if SuggestUnitAI(tc) != "shy" { t.Fatal("expected shy") } } + +func TestUnitAIFromDesc(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) + k := NewUnit(NewCard("misc/king"), m.TileAt(Position{0, 0}), player) + ai := NewUnitAIFromDesc(nil, k, "shy") + if ai == nil { + t.Fatal("ai is nil") + } +} + +func TestShyUnitAI(t *testing.T) { + mapDef := `map: |1- + HST + HSF + TST +symbols: + T: tower + H: house + F: farm + S: street +` + s := NewLocalState() + p := s.AddNewPlayer("muhq", NewDeck()) + o := s.AddNewPlayer("opponent", NewDeck()) + + r := strings.NewReader(mapDef) + m, _ := readMap(r) + s.SetMap(m) + + s.addNewUnit(NewCard("base/knight"), Position{0, 0}, p) + king := s.addNewUnit(NewCard("misc/king"), Position{1, 1}, o) + + ai := NewUnitAI(s, king) + if ai == nil { + t.Fatal("ai is nil") + } + + ai.promptAction() + a, ok := ai.NextAction() + if a == nil { + t.Fatal("Nil action received from shy AI") + } + + s.ResolveAction(a) + pos := Position{2, 2} + if king.Tile().Position != pos { + t.Fatal("king not moving to most distant pos from enemy units", king.Tile().Position) + } + + ai.promptAction() + _, ok = ai.NextAction() + if ok { + t.Fatal("ShyAI did not close its channel") + } +} |
