diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-07-06 11:39:14 -0400 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-07-06 11:49:26 -0400 |
| commit | 7e44005b62ab0de1d40f6527ea21eecfeff0969a (patch) | |
| tree | ea0b2138320794689db41b28947517c12609023a | |
| parent | 793286b8e3e14b3013d0fb7cc69e9c8b28e9d054 (diff) | |
| download | muhqs-game-7e44005b62ab0de1d40f6527ea21eecfeff0969a.tar.gz muhqs-game-7e44005b62ab0de1d40f6527ea21eecfeff0969a.zip | |
fix draft bugs
Do not access an empty slice by index.
Do not assume all received notificarions are DraftPickPrompts.
| -rw-r--r-- | go/game/draft.go | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/go/game/draft.go b/go/game/draft.go index d698abce..5854d23d 100644 --- a/go/game/draft.go +++ b/go/game/draft.go @@ -79,8 +79,8 @@ func (d *Draft) CardsPerPack() int { func (d *Draft) PlayerNames() []string { n := make([]string, 0, len(d.players)) - for i, p := range d.players { - n[i] = p.Name + for _, p := range d.players { + n = append(n, p.Name) } return n } @@ -162,7 +162,7 @@ func (d *Draft) AddPlayer(p *Player) { d.players = append(d.players, p) } -// AddPlayerReplacingAI adds a player to t+e draft replacing the first encountered AI. +// AddPlayerReplacingAI adds a player to the draft replacing the first encountered AI. func (d *Draft) AddPlayerReplacingAI(new *Player) { if new.Ctrl == nil { log.Fatal("added player without control") @@ -195,7 +195,9 @@ func (ctrl *randomDraftAiCtrl) Close() { } func (ctrl *randomDraftAiCtrl) SendNotification(n PlayerNotification) error { - ctrl.pack = n.Context.(PileOfCards) + if n.Valid() && n.Notification == DraftPickPrompt { + ctrl.pack = n.Context.(PileOfCards) + } return nil } |
