summaryrefslogtreecommitdiff
path: root/engine/game.go
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-09-22 15:05:51 +0200
committerewy <ewy0@protonmail.com>2026-09-22 15:05:51 +0200
commit3eacf89dded0121d2a50fb01dec5d8ccbfbbe4ee (patch)
treebce32fd935807c2d5a0daaee76d9a75bdc27f99c /engine/game.go
parent83b2f2e9922f46fe46fd5330e6b38c66d1483ade (diff)
naive auth
Diffstat (limited to 'engine/game.go')
-rw-r--r--engine/game.go45
1 files changed, 37 insertions, 8 deletions
diff --git a/engine/game.go b/engine/game.go
index 8365869..0735958 100644
--- a/engine/game.go
+++ b/engine/game.go
@@ -5,22 +5,24 @@ import (
)
type Turn struct {
- Player *Player
+ Player *Player `json:"-"`
+ PlayerSlot string `json:"Player"`
ActionTaken bool
- Actions []Action
+ Actions []Action
}
type Game struct {
Shadow *pool.Pool
Distance *pool.Pool
- Yin *Player
- Yang *Player
+ Yin *Player `json:"PlayerYin"`
+ Yang *Player `json:"PlayerYang"`
Stack []IsCard
Actions []Action
- CurrentPlayer *Player
+ CurrentPlayer *Player `json:"-"`
+ CurrentPlayerSlot string `json:"CurrentPlayer"`
History []Turn
}
@@ -59,18 +61,45 @@ func (g *Game) Winner() *Player {
func (g *Game) NextTurn() {
current := g.CurrentPlayer.Opponent(g)
g.CurrentPlayer = current
+ playerRef := "UNKNOWN"
+ switch current {
+ case g.Yin:
+ playerRef = "YIN"
+ case g.Yang:
+ playerRef = "YANG"
+ }
g.History = append(g.History, Turn{
- Player: current,
+ Player: current,
ActionTaken: false,
+ PlayerSlot: playerRef,
})
- g.Actions = Interactions(ShuffleDeckAction(g),DrawCardAction(g)),
+ g.CurrentPlayerSlot = playerRef
+ g.Actions = Interactions(ShuffleDeckAction(g), DrawCardAction(g))
}
func (g *Game) CurrentTurn() Turn {
- return g.History[len(g.History) - 1]
+ return g.History[len(g.History)-1]
}
func (g *Game) ActionToHistory(a Action) {
thisTurn := g.History[len(g.History)-1]
thisTurn.Actions = append(thisTurn.Actions, a)
}
+
+func (g *Game) Present(p *Player) Game {
+ localGame := *g
+ switch p {
+ case g.Yin:
+ localGame.Yang.Hide()
+ case g.Yang:
+ localGame.Yin.Hide()
+ }
+ var acs []Action
+ for _, a := range g.Actions {
+ if a.Actor(g) == p {
+ acs = append(acs, a)
+ }
+ }
+ localGame.Actions = acs
+ return localGame
+}