diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-09-05 18:28:47 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-09-05 18:28:47 +0200 |
| commit | 034e176110cc0a27cd20bdfe8522fd0dc73d2346 (patch) | |
| tree | e0198741c94fb3af7777056c031e74100f4f9bb5 /go/game/player.go | |
| parent | 611c8cd048ca216c16da6744ce2052d9dc000c83 (diff) | |
| download | muhqs-game-034e176110cc0a27cd20bdfe8522fd0dc73d2346.tar.gz muhqs-game-034e176110cc0a27cd20bdfe8522fd0dc73d2346.zip | |
implement more prompts and exp1/backup!
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 { |
