aboutsummaryrefslogtreecommitdiff
path: root/go/game/state.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-10-18 12:59:08 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2025-10-18 12:59:08 +0200
commit2c2a2d84a92cda814e0e56d9408e6cbfd68c4fbb (patch)
tree91f5f79807d1aee3993e965d72b6707dbbef77f2 /go/game/state.go
parent6a0013c62f24654529fd589a7de486bf1888a63b (diff)
downloadmuhqs-game-2c2a2d84a92cda814e0e56d9408e6cbfd68c4fbb.tar.gz
muhqs-game-2c2a2d84a92cda814e0e56d9408e6cbfd68c4fbb.zip
support phase change triggers and implement relic
Diffstat (limited to 'go/game/state.go')
-rw-r--r--go/game/state.go47
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) {