diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-09-05 17:47:09 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-09-05 17:57:36 +0200 |
| commit | 611c8cd048ca216c16da6744ce2052d9dc000c83 (patch) | |
| tree | 9e4119fa27a7839fab0329ff29d65b0a6f934087 | |
| parent | 18dfde76df708631089d39f63394f3a8c1dc9df7 (diff) | |
| download | muhqs-game-611c8cd048ca216c16da6744ce2052d9dc000c83.tar.gz muhqs-game-611c8cd048ca216c16da6744ce2052d9dc000c83.zip | |
support 'allied unit' alias to 'unit you control'
| -rw-r--r-- | go/game/targets.go | 4 | ||||
| -rw-r--r-- | go/game/targets_test.go | 43 |
2 files changed, 46 insertions, 1 deletions
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") + } +} |
