Fix shop action costs and pass semantics.
Only buying costs gold; selling and trading (Triple) are free. Pass is now a final action, legal only at or under the pet limit: it forfeits remaining gold and ends that player's shopping for the round, with the shop closing once everyone has passed. That makes the separate cleanup phase unreachable (you sell down in-shop before passing), so it is removed. The client asks for confirmation before passing, and the bot knows buys are the only coin sink, when passing is legal, and that it must sell down before it can pass.
This commit is contained in:
+26
-70
@@ -28,8 +28,7 @@ type Phase string
|
||||
|
||||
const (
|
||||
PhaseLobby Phase = "lobby" // waiting for players
|
||||
PhaseShop Phase = "shop" // players take turns spending coins
|
||||
PhaseCleanup Phase = "cleanup" // forced discard down to MaxPets pets
|
||||
PhaseShop Phase = "shop" // players take turns acting until all pass
|
||||
PhaseArrange Phase = "arrange" // players order their decks for battle
|
||||
PhaseBattle Phase = "battle" // battle resolved; players review the log
|
||||
PhaseGameOver Phase = "gameover" // all rounds played
|
||||
@@ -45,7 +44,7 @@ type Player struct {
|
||||
Coins int `json:"coins"`
|
||||
Deck []Card `json:"deck"`
|
||||
Trophies int `json:"trophies"`
|
||||
Ready bool `json:"ready"` // arrange submitted / battle acknowledged
|
||||
Ready bool `json:"ready"` // shop passed / arrange submitted / battle acknowledged
|
||||
Connected bool `json:"connected"`
|
||||
// TripledThisRound records whether the player used the Triple (trade-in)
|
||||
// action during the current round's shop (Bison's Battle Prep).
|
||||
@@ -280,19 +279,20 @@ func (g *Game) requireShopTurn(playerID string) (*Player, error) {
|
||||
if g.Pending != nil {
|
||||
return nil, fmt.Errorf("%w: finish your trade first", ErrInvalidAction)
|
||||
}
|
||||
if p.Coins <= 0 {
|
||||
return nil, ErrNoCoins
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// Buy spends one coin to take the card at rowIdx into the player's deck.
|
||||
// The slot refills from the current round's tier deck.
|
||||
// The slot refills from the current round's tier deck. Buying is the only
|
||||
// action that costs gold.
|
||||
func (g *Game) Buy(playerID string, rowIdx int) error {
|
||||
p, err := g.requireShopTurn(playerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if p.Coins <= 0 {
|
||||
return ErrNoCoins
|
||||
}
|
||||
if rowIdx < 0 || rowIdx >= len(g.ShopRow) || g.ShopRow[rowIdx].ID == "" {
|
||||
return fmt.Errorf("%w: no card in that shop slot", ErrInvalidAction)
|
||||
}
|
||||
@@ -307,8 +307,8 @@ func (g *Game) Buy(playerID string, rowIdx int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Sell spends one coin to sell any number (>=1) of the player's cards: each
|
||||
// becomes an apple, and Sell effects on the sold cards fire.
|
||||
// Sell converts any number (>=1) of the player's cards: each becomes an
|
||||
// apple, and Sell effects on the sold cards fire. Selling is free.
|
||||
func (g *Game) Sell(playerID string, cardIDs []string) error {
|
||||
p, err := g.requireShopTurn(playerID)
|
||||
if err != nil {
|
||||
@@ -320,7 +320,6 @@ func (g *Game) Sell(playerID string, cardIDs []string) error {
|
||||
if err := g.sellCards(p, cardIDs); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Coins--
|
||||
g.advanceShopTurn()
|
||||
return nil
|
||||
}
|
||||
@@ -403,9 +402,9 @@ func hasBuyEffect(c Card) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// TradeStart spends one coin and three same-suit pets from the player's deck
|
||||
// to reveal the top two cards of the next tier's deck. The player must then
|
||||
// call TradeChoose before anything else happens.
|
||||
// TradeStart trades three same-suit pets from the player's deck to reveal
|
||||
// the top two cards of the next tier's deck — a free action. The player must
|
||||
// then call TradeChoose before anything else happens.
|
||||
func (g *Game) TradeStart(playerID string, cardIDs []string) error {
|
||||
p, err := g.requireShopTurn(playerID)
|
||||
if err != nil {
|
||||
@@ -444,7 +443,6 @@ func (g *Game) TradeStart(playerID string, cardIDs []string) error {
|
||||
traded = append(traded, p.Deck[idx])
|
||||
p.Deck = slices.Delete(p.Deck, idx, idx+1)
|
||||
}
|
||||
p.Coins--
|
||||
p.TripledThisRound = true
|
||||
// The discarded trio is public — everyone sees what was given up — even
|
||||
// though the pet ultimately chosen stays secret (see TradeChoose).
|
||||
@@ -505,7 +503,7 @@ func (g *Game) TradeChoose(playerID string, pick int) error {
|
||||
// free and off-turn — a testing aid gated behind the server's DEBUG flag, not
|
||||
// a normal action. No buy effects fire.
|
||||
func (g *Game) DebugGrant(playerID, name string) error {
|
||||
if g.Phase != PhaseShop && g.Phase != PhaseCleanup {
|
||||
if g.Phase != PhaseShop {
|
||||
return ErrWrongPhase
|
||||
}
|
||||
p := g.PlayerByID(playerID)
|
||||
@@ -520,81 +518,39 @@ func (g *Game) DebugGrant(playerID, name string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Pass forfeits the player's remaining coins and ends their shopping.
|
||||
// Pass is a player's final shop action: it ends their shopping for the rest
|
||||
// of the round, forfeiting any remaining coins. It is only legal at or under
|
||||
// the pet limit — a player holding too many pets must sell down first.
|
||||
func (g *Game) Pass(playerID string) error {
|
||||
p, err := g.requireShopTurn(playerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if p.PetCount() > MaxPets {
|
||||
return fmt.Errorf("%w: sell down to %d pets before passing", ErrInvalidAction, MaxPets)
|
||||
}
|
||||
p.Coins = 0
|
||||
g.logf(p.Seat, "✋", "%s passed.", p.Name)
|
||||
p.Ready = true
|
||||
g.logf(p.Seat, "✋", "%s passed — done shopping this round.", p.Name)
|
||||
g.advanceShopTurn()
|
||||
return nil
|
||||
}
|
||||
|
||||
// advanceShopTurn hands the turn to the next player who still has coins, or
|
||||
// moves the game onward when everyone is spent.
|
||||
// advanceShopTurn hands the turn to the next player still shopping, or moves
|
||||
// on to arranging once everyone has passed. Passing is the only way out of
|
||||
// the shop, and it requires being at the pet limit, so no cleanup step is
|
||||
// needed here.
|
||||
func (g *Game) advanceShopTurn() {
|
||||
for i := 1; i <= len(g.Players); i++ {
|
||||
seat := (g.Turn + i) % len(g.Players)
|
||||
if g.Players[seat].Coins > 0 {
|
||||
if !g.Players[seat].Ready {
|
||||
g.Turn = seat
|
||||
return
|
||||
}
|
||||
}
|
||||
g.endShop()
|
||||
}
|
||||
|
||||
// endShop moves to forced discard if anyone is over the pet limit, otherwise
|
||||
// straight to arranging.
|
||||
func (g *Game) endShop() {
|
||||
over := false
|
||||
for _, p := range g.Players {
|
||||
p.Ready = p.PetCount() <= MaxPets
|
||||
if !p.Ready {
|
||||
over = true
|
||||
}
|
||||
}
|
||||
if over {
|
||||
g.Phase = PhaseCleanup
|
||||
return
|
||||
}
|
||||
g.beginArrange()
|
||||
}
|
||||
|
||||
// CleanupSell performs the forced end-of-shop sale: the player must sell
|
||||
// exactly their excess pets (each becomes an apple; Sell effects fire).
|
||||
func (g *Game) CleanupSell(playerID string, cardIDs []string) error {
|
||||
if g.Phase != PhaseCleanup {
|
||||
return ErrWrongPhase
|
||||
}
|
||||
p := g.PlayerByID(playerID)
|
||||
if p == nil {
|
||||
return errors.New("unknown player")
|
||||
}
|
||||
excess := p.PetCount() - MaxPets
|
||||
if excess <= 0 {
|
||||
return fmt.Errorf("%w: you are not over the pet limit", ErrInvalidAction)
|
||||
}
|
||||
if len(cardIDs) != excess {
|
||||
return fmt.Errorf("%w: sell exactly %d pets", ErrInvalidAction, excess)
|
||||
}
|
||||
for _, id := range cardIDs {
|
||||
idx := p.cardIndex(id)
|
||||
if idx < 0 || !p.Deck[idx].IsPet() {
|
||||
return fmt.Errorf("%w: pick pets from your deck", ErrInvalidAction)
|
||||
}
|
||||
}
|
||||
if err := g.sellCards(p, cardIDs); err != nil {
|
||||
return err
|
||||
}
|
||||
p.Ready = true
|
||||
if g.allReady() {
|
||||
g.beginArrange()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Game) allReady() bool {
|
||||
for _, p := range g.Players {
|
||||
if !p.Ready {
|
||||
|
||||
Reference in New Issue
Block a user