aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-07-24 17:40:16 -0400
committerFlorian Fischer <florian.fischer@muhq.space>2025-07-28 18:03:10 +0200
commit76f79f077dbe3ccc7fe12d803231856396573e3a (patch)
treed88212496dc8809c755754242f862ed15fa032f4
parentbbf0d66613661432b53c83c2a279bb00c233a38a (diff)
downloadmuhqs-game-76f79f077dbe3ccc7fe12d803231856396573e3a.tar.gz
muhqs-game-76f79f077dbe3ccc7fe12d803231856396573e3a.zip
support options candidates for disjunctions
-rw-r--r--go/game/targets.go18
-rw-r--r--go/game/targets_test.go75
2 files changed, 82 insertions, 11 deletions
diff --git a/go/game/targets.go b/go/game/targets.go
index 613d3ea0..473b26b0 100644
--- a/go/game/targets.go
+++ b/go/game/targets.go
@@ -821,14 +821,19 @@ func parseCardTargetConstraint(desc string, s *LocalState, action Action) []Targ
}
func (t *Target) candidates() []interface{} {
+ c := []any{}
if strings.Contains(t.desc, "unit") ||
strings.Contains(t.desc, "artifact") ||
strings.Contains(t.desc, "permanent") {
- return utils.TypedSliceToInterfaceSlice(t.s.Permanents())
- } else if strings.Contains(t.desc, "tile") {
- return utils.TypedSliceToInterfaceSlice(t.s.Map().AllTiles())
- } else if strings.Contains(t.desc, "card") {
+ c = append(c, utils.TypedSliceToInterfaceSlice(t.s.Permanents())...)
+ }
+
+ if strings.Contains(t.desc, "tile") {
+ c = append(c, utils.TypedSliceToInterfaceSlice(t.s.Map().AllTiles())...)
+ }
+
+ if strings.Contains(t.desc, "card") {
cards := NewPileOfCards()
switch t.desc {
case "hand card":
@@ -848,9 +853,8 @@ func (t *Target) candidates() []interface{} {
default:
log.Panicf("Unimplemented card options for %s", t.desc)
}
- return utils.TypedSliceToInterfaceSlice(cards.Cards())
+ c = append(c, utils.TypedSliceToInterfaceSlice(cards.Cards())...)
}
- log.Panicf("Unimplemented target options for %s", t.desc)
- return nil
+ return c
}
diff --git a/go/game/targets_test.go b/go/game/targets_test.go
index b7d1cda0..092e2bb6 100644
--- a/go/game/targets_test.go
+++ b/go/game/targets_test.go
@@ -5,6 +5,75 @@ import (
"testing"
)
+func TestTileTargets(t *testing.T) {
+ mapDef := `map: |1-
+ HSTS
+ HSFS
+ TSWS
+
+symbols:
+ T: tower
+ H: house
+ F: farm
+ S: street
+ W: deep water
+`
+ s := NewLocalState()
+ r := strings.NewReader(mapDef)
+ m, _ := readMap(r)
+ s.SetMap(m)
+
+ p := s.AddNewPlayer("player", NewDeck())
+ u := s.addNewUnit(NewCard("base/archer"), Position{1, 1}, p)
+ s.addNewUnit(NewCard("base/cavalry"), Position{1, 2}, p)
+
+ a := newFullAction(u,
+ func(Action) ActionResolveFunc { var f ActionResolveFunc; return f },
+ "mock full action")
+
+ tDesc := newTargetDesc("tile")
+ trgt := newTarget(s, tDesc, a)
+ opts := trgt.Options()
+ if len(opts) != 12 {
+ t.Fatal("expexted 12 candidates not:", len(opts))
+ }
+
+ tDesc = newTargetDesc("water tile")
+ trgt = newTarget(s, tDesc, a)
+ opts = trgt.Options()
+ if len(opts) != 1 {
+ t.Fatal("expected 1 water candidates not:", len(opts))
+ }
+
+ tDesc = newTargetDesc("free tile")
+ trgt = newTarget(s, tDesc, a)
+ opts = trgt.Options()
+ if len(opts) != 10 {
+ t.Fatal("expected 10 free candidates not:", len(opts))
+ }
+
+ tDesc = newTargetDesc("available tile")
+ trgt = newTarget(s, tDesc, a)
+ opts = trgt.Options()
+ if len(opts) != 9 {
+ t.Fatal("expected 9 available candidates not:", len(opts))
+ }
+
+ tDesc = newTargetDesc("adjacent tile")
+ trgt = newTarget(s, tDesc, a)
+ opts = trgt.Options()
+ if len(opts) != 9 {
+ t.Fatal("expected 9 available candidates not:", len(opts))
+ }
+
+ tDesc = newTargetDesc("adjacent available tile")
+ trgt = newTarget(s, tDesc, a)
+ opts = trgt.Options()
+ if len(opts) != 6 {
+ t.Fatal("expected 6 available candidates not:", len(opts))
+ }
+}
+
func TestDisjunction(t *testing.T) {
mapDef := `map: |1-
HST
@@ -18,12 +87,10 @@ symbols:
W: deep water
`
s := NewLocalState()
- r := strings.NewReader(mapDef)
- m, _ := readMap(r)
+ m, _ := readMap(strings.NewReader(mapDef))
s.SetMap(m)
- s.AddNewPlayer("player", NewDeck())
- p := s.Players()[0]
+ p := s.AddNewPlayer("player", NewDeck())
pioneer := NewUnit(NewCard("base/pioneer"), s.Map().TileAt(Position{1, 1}), p)
s.addPermanent(pioneer)