From 611c8cd048ca216c16da6744ce2052d9dc000c83 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Fri, 5 Sep 2025 17:47:09 +0200 Subject: support 'allied unit' alias to 'unit you control' --- go/game/targets.go | 4 +++- go/game/targets_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) (limited to 'go/game') diff --git a/go/game/targets.go b/go/game/targets.go index 6b5a6eb9..9bfd1378 100644 --- a/go/game/targets.go +++ b/go/game/targets.go @@ -576,7 +576,7 @@ func parseUnitTargetConstraint(desc string, _ *LocalState, action Action) []Targ constraints = append(constraints, enemyPermanentTargetConstraint(action)) } - if strings.Contains(desc, "you control") { + if strings.Contains(desc, "you control") || strings.Contains(desc, "allied unit") { constraints = append(constraints, controlledPermanentTargetConstraint(action)) } @@ -821,6 +821,8 @@ func parseCardTargetConstraint(desc string, s *LocalState, action Action) []Targ pocDesc = "discard pile" } + // TODO: support player specific constraints + for _, p := range origins { switch pocDesc { case "hand": diff --git a/go/game/targets_test.go b/go/game/targets_test.go index 672df356..07df4b60 100644 --- a/go/game/targets_test.go +++ b/go/game/targets_test.go @@ -3,6 +3,8 @@ package game import ( "strings" "testing" + + "muhq.space/muhqs-game/go/utils" ) func TestTileTargets(t *testing.T) { @@ -214,3 +216,44 @@ symbols: t.Fatalf("%v not a valid target for %v", sword, fa) } } + +func TestUnitConstraint(t *testing.T) { + s, _, p, o := newMockState() + + a := s.addNewUnit(NewCard("base/archer"), Position{0, 0}, p) + oa := s.addNewUnit(NewCard("base/archer"), Position{1, 1}, o) + + desc := newTargetDesc("enemy unit") + // Use a dummy pass action to pass the player to the target constraints + target := newTarget(s, desc, NewPassPriority(p)) + options := target.Options() + if !utils.InterfaceSliceContains(options, oa) { + t.Fatal("enemy units does not contain opponent's archer") + } + if utils.InterfaceSliceContains(options, a) { + t.Fatal("enemy units contain own archer") + } + + desc = newTargetDesc("allied unit") + // Use a dummy pass action to pass the player to the target constraints + target = newTarget(s, desc, NewPassPriority(p)) + options = target.Options() + if utils.InterfaceSliceContains(options, oa) { + t.Fatal("'allied units' does contain opponent's archer") + } + if !utils.InterfaceSliceContains(options, a) { + t.Fatal("'allied units' does not contain own archer") + } + + // Test for controlled units + oa.changeController(p) + desc = newTargetDesc("unit you control") + target = newTarget(s, desc, NewPassPriority(p)) + options = target.Options() + if !utils.InterfaceSliceContains(options, oa) { + t.Fatal("'units you control' does not contain controlled archer owned by the oponent") + } + if !utils.InterfaceSliceContains(options, a) { + t.Fatal("'units you control' does not contain own archer") + } +} -- cgit v1.2.3