diff options
Diffstat (limited to 'go/game/state.go')
| -rw-r--r-- | go/game/state.go | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/go/game/state.go b/go/game/state.go index a9c2f638..1ab3c95d 100644 --- a/go/game/state.go +++ b/go/game/state.go @@ -153,6 +153,12 @@ func (s *LocalState) IsActivePlayer(p *Player) bool { return s.activePlayerId == p.Id } +func (s *LocalState) changePhase(next PhaseType) []*Player { + s.activePhase = next + s.fireEvent(newPhaseChangeEvent()) + return s.stateBasedActions() +} + func (s *LocalState) Loop() []*Player { // Prepare the map if s._map.Prepare != nil { @@ -177,6 +183,7 @@ func (s *LocalState) Loop() []*Player { s.activePlayerId = p.Id p.Turn++ + // Shuffle discard pile into empty deck if p.Deck.IsEmpty() { e := newShuffleEvent(p, []PileOfCards{p.DiscardPile}) s.fireEvent(e) @@ -185,42 +192,50 @@ func (s *LocalState) Loop() []*Player { p.Deck.Shuffle(s.Rand) } - s.activePhase = Phases.DrawStep + // Switch to draw step without a priority round + if w := s.changePhase(Phases.DrawStep); len(w) > 0 { + return w + } p.Draw() - s.activePhase = Phases.UpkeepPhase + // Switch to upkeep without a priority round + if w := s.changePhase(Phases.UpkeepPhase); len(w) > 0 { + return w + } winners := p.upkeep() if len(winners) > 0 { return winners } - winners = s.phaseChange() + // Full phase change to the actions phase with a priority round + winners = s.phaseChange(Phases.ActionPhase) if len(winners) > 0 { return winners } - s.activePhase = Phases.ActionPhase winners = p.actionPhase() if len(winners) > 0 { return winners } - winners = s.phaseChange() + + // Full phase change to the buy phase with a priority round + winners = s.phaseChange(Phases.BuyPhase) if len(winners) > 0 { return winners } - s.activePhase = Phases.BuyPhase winners = p.buyPhase() if len(winners) > 0 { return winners } - winners = s.phaseChange() + + // Full phase change to the discard step with a priority round + winners = s.phaseChange(Phases.DiscardStep) if len(winners) > 0 { return winners } - - s.activePhase = Phases.DiscardStep p.discardStep() + // End the trun after discarding without a priority round winners = s.endOfTurn() if len(winners) > 0 { return winners @@ -499,12 +514,13 @@ func (s *LocalState) allPassing(skipFirst bool) (bool, []*Player) { return true, nil } -func (s *LocalState) phaseChange() []*Player { +func (s *LocalState) phaseChange(next PhaseType) (w []*Player) { skipFirst := true for { - passing, w := s.allPassing(skipFirst) + var passing bool + passing, w = s.allPassing(skipFirst) if len(w) > 0 { - return w + break } if passing { break @@ -512,12 +528,15 @@ func (s *LocalState) phaseChange() []*Player { w = s.stack.resolve() if len(w) > 0 { - return w + break } skipFirst = false } - return nil + + s.changePhase(next) + + return } func (s *LocalState) broadcastNotification(n PlayerNotification) { |
