diff options
Diffstat (limited to 'go/game/player.go')
| -rw-r--r-- | go/game/player.go | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/go/game/player.go b/go/game/player.go index a8372040..b3cdfe0f 100644 --- a/go/game/player.go +++ b/go/game/player.go @@ -224,37 +224,59 @@ func (p *Player) discardStep() { } cards := p.PromptHandCardSelection(0, p.Hand.Size()) - for _, c := range cards { - p.DiscardCard(c) - } + p.discardCards(cards) } -func (p *Player) PromptHandCardSelection(min, max int) []*Card { - p.Ctrl.SendNotification(newHandCardSelectionPrompt(p, min, max)) +func (p *Player) Prompt(n PlayerNotification) Action { + p.Ctrl.SendNotification(n) _a, err := p.Ctrl.RecvAction() if err != nil { // FIXME } switch a := _a.(type) { - case *TargetSelection: - err := a.CheckTargets(p.gameState) - if err != nil { - log.Panicf("Invalid hand card selection: %v", err) - } - - return utils.InterfaceSliceToTypedSlice[*Card](a.Target().sel) case *PassPriority: return nil case *ConcedeAction: p.concede() return nil default: - log.Panicf("Unexpected response type %T for hand card selection", a) + return a + } +} + +func PromptSelection[T any](p *Player, n PlayerNotification) []T { + _a := p.Prompt(n) + if _a == nil { + return nil + } + + switch a := _a.(type) { + case *TargetSelection: + err := a.CheckTargets(p.gameState) + if err != nil { + log.Panicf("Invalid selection: %v", err) + } + + return utils.InterfaceSliceToTypedSlice[T](a.Target().sel) + default: + log.Panicf("Unexpected response type %T for selection", a) } return nil } +func (p *Player) PromptHandCardSelection(min, max int) []*Card { + return PromptSelection[*Card](p, newHandCardSelectionPrompt(p, min, max)) +} + +func (p *Player) PromptAlliedUnitSelection(min, max int) []*Unit { + return PromptSelection[*Unit](p, newAlliedUnitSelectionPrompt(p, min, max)) +} + +func (p *Player) PromptTilesSelection(c TargetConstraintFunc, min, max int) []*Tile { + return PromptSelection[*Tile](p, newTileSelectionPrompt(p, c, min, max)) +} + func (p *Player) Draw() { toDraw := p.DrawPerTurn - p.Hand.Size() if toDraw < 1 { |
