From d52a41bdcb587abe57f7d581d260b4be948dcc2a Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Fri, 17 Feb 2023 13:40:42 +0100 Subject: implement targets candidates for hand cards --- go/game/pileOfCards.go | 4 ++++ go/game/targets.go | 26 ++++++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) (limited to 'go/game') diff --git a/go/game/pileOfCards.go b/go/game/pileOfCards.go index f88dfe93..5edae617 100644 --- a/go/game/pileOfCards.go +++ b/go/game/pileOfCards.go @@ -43,6 +43,10 @@ func (poc *PileOfCardsBase) Cards() []*Card { return poc.cards } +func (poc *PileOfCardsBase) AddPoc(toAdd PileOfCards) { + poc.AddCards(toAdd.Cards()) +} + func (poc *PileOfCardsBase) AddCards(cards []*Card) { for _, card := range cards { poc.AddCard(card) diff --git a/go/game/targets.go b/go/game/targets.go index 2ef88665..75f3f53c 100644 --- a/go/game/targets.go +++ b/go/game/targets.go @@ -126,7 +126,7 @@ func (t *Target) HasSelection() bool { return len(t.sel) > 0 } func (t *Target) ClearSelection() { t.sel = []interface{}{} } func (t *Target) Options() (options []interface{}) { - candidates := targetCandidates(t.desc, t.s) + candidates := t.candidates() for _, candidate := range candidates { if err := t.constraint(candidate); err == nil { @@ -524,16 +524,22 @@ func parseCardTargetConstraint(desc string, s *State, action Action) []TargetCon return constraints } -func targetCandidates(desc string, s *State) []interface{} { - if strings.Contains(desc, "unit") || - strings.Contains(desc, "artifact") || - strings.Contains(desc, "permanent") { - - return utils.TypedSliceToInterfaceSlice(s.Permanents) - } else if strings.Contains(desc, "tile") { - return utils.TypedSliceToInterfaceSlice(s.Map.AllTiles()) +func (t *Target) candidates() []interface{} { + 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 t.desc == "hand card" { + cards := NewPileOfCards() + for _, p := range t.s.Players { + cards.AddPoc(p.Hand) + } + return utils.TypedSliceToInterfaceSlice(cards.Cards()) } - log.Panicf("Unimplemented target options for %s", desc) + log.Panicf("Unimplemented target options for %s", t.desc) return nil } -- cgit v1.2.3