Implement priority token.
This commit is contained in:
+21
-13
@@ -76,18 +76,23 @@ type PendingTrade struct {
|
||||
// Game is the complete authoritative state. It is a pure state machine: no
|
||||
// goroutines, no clocks, no I/O. Callers are responsible for locking.
|
||||
type Game struct {
|
||||
ID string `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Phase Phase `json:"phase"`
|
||||
Round int `json:"round"` // 1-based
|
||||
Players []*Player `json:"players"`
|
||||
ShopDecks [][]Card `json:"shopDecks"` // index 0 = tier 1
|
||||
ShopRow []Card `json:"shopRow"` // empty ID = empty slot
|
||||
Turn int `json:"turn"` // seat with the current shop turn
|
||||
Pending *PendingTrade `json:"pending,omitempty"`
|
||||
Battle *BattleResult `json:"battle,omitempty"` // most recent battle
|
||||
NextCardID int `json:"nextCardId"`
|
||||
WinnerSeat int `json:"winnerSeat"` // set at gameover; -1 = tie
|
||||
ID string `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Phase Phase `json:"phase"`
|
||||
Round int `json:"round"` // 1-based
|
||||
Players []*Player `json:"players"`
|
||||
ShopDecks [][]Card `json:"shopDecks"` // index 0 = tier 1
|
||||
ShopRow []Card `json:"shopRow"` // empty ID = empty slot
|
||||
Turn int `json:"turn"` // seat with the current shop turn
|
||||
// PrioritySeat holds the priority token: that seat shops first each round
|
||||
// and wins simultaneity races in battle. Assigned randomly at game start;
|
||||
// a battle winner hands it to the loser, a loser keeps it, a draw leaves
|
||||
// it put.
|
||||
PrioritySeat int `json:"prioritySeat"`
|
||||
Pending *PendingTrade `json:"pending,omitempty"`
|
||||
Battle *BattleResult `json:"battle,omitempty"` // most recent battle
|
||||
NextCardID int `json:"nextCardId"`
|
||||
WinnerSeat int `json:"winnerSeat"` // set at gameover; -1 = tie
|
||||
|
||||
// RollDie overrides the rock die (faces 0,0,1,1,2,2) for tests. Nil
|
||||
// (including after loading from storage) means a fair random roll.
|
||||
@@ -199,6 +204,8 @@ func (g *Game) PlayerByID(id string) *Player {
|
||||
|
||||
func (g *Game) start() {
|
||||
g.Round = 1
|
||||
// The priority token starts with a random seat.
|
||||
g.PrioritySeat = randInt(len(g.Players))
|
||||
g.startShopRound()
|
||||
}
|
||||
|
||||
@@ -216,7 +223,8 @@ func (g *Game) startShopRound() {
|
||||
for i := range g.ShopRow {
|
||||
g.ShopRow[i] = g.drawFromTier(g.Round)
|
||||
}
|
||||
g.Turn = (g.Round - 1) % len(g.Players)
|
||||
// The priority-token holder shops first.
|
||||
g.Turn = g.PrioritySeat
|
||||
}
|
||||
|
||||
// drawFromTier pops the top card of the given tier's deck (1-based tier).
|
||||
|
||||
Reference in New Issue
Block a user