Keep deck storted sensibly during shop phase.
This commit is contained in:
@@ -410,12 +410,36 @@ func (g *Game) startShopRound() {
|
|||||||
for _, c := range slices.Clone(p.Deck) {
|
for _, c := range slices.Clone(p.Deck) {
|
||||||
g.applyShopTrigger(p, c, TriggerShopStart)
|
g.applyShopTrigger(p, c, TriggerShopStart)
|
||||||
}
|
}
|
||||||
|
g.sortShopDeck(p)
|
||||||
}
|
}
|
||||||
// The priority-token holder shops first.
|
// The priority-token holder shops first.
|
||||||
g.Turn = g.PrioritySeat
|
g.Turn = g.PrioritySeat
|
||||||
g.logf(-1, "🛒", "Round %d — shop opens (%s goes first).", g.Round, g.Players[g.PrioritySeat].Name)
|
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).
|
// drawFromTier pops the top card of the given tier's deck (1-based tier).
|
||||||
// Returns a zero Card if the deck is empty.
|
// Returns a zero Card if the deck is empty.
|
||||||
func (g *Game) drawFromTier(tier int) Card {
|
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
|
// the shop, and it requires being at the pet limit, so no cleanup step is
|
||||||
// needed here.
|
// needed here.
|
||||||
func (g *Game) advanceShopTurn() {
|
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++ {
|
for i := 1; i <= len(g.Players); i++ {
|
||||||
seat := (g.Turn + i) % len(g.Players)
|
seat := (g.Turn + i) % len(g.Players)
|
||||||
if !g.Players[seat].Ready {
|
if !g.Players[seat].Ready {
|
||||||
|
|||||||
Reference in New Issue
Block a user