From 4fb5c5929f7d482bc97bedd93530dd6acc99a1b9 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Mon, 27 Jul 2026 09:29:07 -0400 Subject: [PATCH] Keep deck storted sensibly during shop phase. --- internal/game/game.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/internal/game/game.go b/internal/game/game.go index 5f6d8aa..3604a91 100644 --- a/internal/game/game.go +++ b/internal/game/game.go @@ -410,12 +410,36 @@ func (g *Game) startShopRound() { for _, c := range slices.Clone(p.Deck) { g.applyShopTrigger(p, c, TriggerShopStart) } + g.sortShopDeck(p) } // The priority-token holder shops first. g.Turn = g.PrioritySeat g.logf(-1, "🛒", "Round %d — shop opens (%s goes first).", g.Round, g.Players[g.PrioritySeat].Name) } +// sortShopDeck stably reorders a player's deck for the shop's default +// display: pets first, then perk foods, then everything else (apples and +// other loose foods). Deck order carries no battle meaning during the shop — +// the battle uses the permutation each player submits in the arrange phase +// (see SubmitOrder) — so this is purely a cosmetic default that keeps freshly +// bought pets grouped at the front. The stable sort preserves buy order +// within each category. +func (g *Game) sortShopDeck(p *Player) { + rank := func(c Card) int { + switch { + case c.IsPet(): + return 0 + case c.IsFood() && c.Perk: + return 1 + default: + return 2 + } + } + slices.SortStableFunc(p.Deck, func(a, b Card) int { + return rank(a) - rank(b) + }) +} + // drawFromTier pops the top card of the given tier's deck (1-based tier). // Returns a zero Card if the deck is empty. func (g *Game) drawFromTier(tier int) Card { @@ -1011,6 +1035,10 @@ func (g *Game) Pass(playerID string) error { // the shop, and it requires being at the pet limit, so no cleanup step is // needed here. func (g *Game) advanceShopTurn() { + // The player who just acted may have changed their deck (bought, sold, + // traded, or triggered an apple-granting effect); keep it in the shop's + // default order for them before handing off. + g.sortShopDeck(g.Players[g.Turn]) for i := 1; i <= len(g.Players); i++ { seat := (g.Turn + i) % len(g.Players) if !g.Players[seat].Ready {