package game import ( "strings" "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 HSF TSW symbols: T: tower H: house F: farm S: street W: deep water ` s := NewLocalState() m, _ := readMap(strings.NewReader(mapDef)) s.SetMap(m) p := s.AddNewPlayer("player", NewDeck()) pioneer := NewUnit(NewCard("base/pioneer"), s.Map().TileAt(Position{1, 1}), p) s.addPermanent(pioneer) sword := newEquipmentFromPath("base/sword", s.Map().TileAt(Position{0, 1}), p) s.addPermanent(sword) fa := pioneer.FullActions[0] targets := fa.Targets() if err := targets.AddSelection(s.Map().TileAt(Position{1, 1})); err != nil { t.Fatalf("TileAt(1,1) not a valid target for %v", fa) } if err := targets.CheckTargets(s); err != nil { t.Fatalf("TileAt(1,1) not a valid target for %v", fa) } targets.ClearSelections() if err := targets.AddSelection(sword); err != nil { t.Fatalf("%v not a valid target for %v", sword, fa) } if err := targets.CheckTargets(s); err != nil { t.Fatalf("%v not a valid target for %v", sword, fa) } }