From 3d36f5c92ec204f72d55df5b41e9bacdf5e87ba8 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Tue, 19 Aug 2025 15:37:09 +0200 Subject: fix spawn tile constraint for water spawns This is not a general solution because spawns could be a valid tile type constraint as well as meaning available spawn tiles. The separation and a clean implementation is still a TODO. --- go/game/targets_test.go | 67 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) (limited to 'go/game/targets_test.go') diff --git a/go/game/targets_test.go b/go/game/targets_test.go index ae451dbf..eed94f4f 100644 --- a/go/game/targets_test.go +++ b/go/game/targets_test.go @@ -9,7 +9,7 @@ func TestTileTargets(t *testing.T) { mapDef := `map: |1- HSTS HSFS - TSWS + TSWD symbols: T: tower @@ -17,6 +17,7 @@ symbols: F: farm S: street W: deep water + D: docks ` s := NewLocalState() r := strings.NewReader(mapDef) @@ -72,6 +73,70 @@ symbols: if len(opts) != 6 { t.Fatal("expected 6 available candidates not:", len(opts)) } + + fisher := NewCard("nautics/fisher") + p.Hand.AddCard(fisher) + pa := NewPlayAction(p, fisher) + opts = pa.Target().Options() + if len(opts) != 1 { + t.Fatal("expected 1 available candidates not:", len(opts)) + } +} + +func TestSpawnTargets(t *testing.T) { + s := NewLocalState() + m, _ := GetMap("the-kraken") + s.SetMap(m) + + s.activePhase = actionPhase + + p := s.AddNewPlayer("player", NewDeck()) + ctrl := newMockPlayerControl(p) + ctrl.actionToSend = NewPassPriority(p) + p.Ctrl = ctrl + + p.gainResource(2) + + farmer := NewCard("misc/farmer") + p.Hand.AddCard(farmer) + fisher := NewCard("nautics/fisher") + p.Hand.AddCard(fisher) + + pa := NewPlayAction(p, farmer) + if !pa.Target().RequireSelection() { + t.Fatal("playing farmer has not require selection") + } + if !pa.Target().AllowSelection() { + t.Fatal("playing farmer has no valid targets") + } + farmerPos := Position{3, 13} + err := pa.Target().AddSelection(m.TileAt(farmerPos)) + if err != nil { + t.Fatal("Not allowed to play farmer at:", farmerPos) + } + s.declareAction(pa) + if s.stack.IsEmpty() { + t.Fatal("farmer play action not declared") + } + s.stack.resolve() + + pa2 := NewPlayAction(p, fisher) + if !pa2.Target().RequireSelection() { + t.Fatal("playing fisher has not require selection") + } + if !pa2.Target().AllowSelection() { + t.Fatal("playing fisher has no valid targets") + } + fisherPos := Position{3, 10} + pa2.Target().AddSelection(m.TileAt(fisherPos)) + if err != nil { + t.Fatal("Not allowed to play fisher at:", fisherPos) + } + s.declareAction(pa2) + if s.stack.IsEmpty() { + t.Fatal("fisher play action not declared") + } + s.stack.resolve() } func TestFlexAttackTargets(t *testing.T) { -- cgit v1.2.3