aboutsummaryrefslogtreecommitdiff
path: root/go/game/winCondition.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2024-12-27 12:40:19 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:58 +0100
commit4e2ab55d345fd5e5c5d2d5bc56948611b15564d5 (patch)
treec6998ac54687c442ad0baa541edd0fbf917b1308 /go/game/winCondition.go
parent5aa8e7ddbc41aed55e7918e6afaec0b5c07fa510 (diff)
downloadmuhqs-game-4e2ab55d345fd5e5c5d2d5bc56948611b15564d5.tar.gz
muhqs-game-4e2ab55d345fd5e5c5d2d5bc56948611b15564d5.zip
introduce game.State interface abstraction
This allows to not use the internal game state directly from client code.
Diffstat (limited to 'go/game/winCondition.go')
-rw-r--r--go/game/winCondition.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/go/game/winCondition.go b/go/game/winCondition.go
index 4db36e1d..4204ccb1 100644
--- a/go/game/winCondition.go
+++ b/go/game/winCondition.go
@@ -4,9 +4,9 @@ import (
"golang.org/x/exp/slices"
)
-func KingGame(s *State) []*Player {
+func KingGame(s *LocalState) []*Player {
foundKings := map[*Player]struct{}{}
- for _, u := range s.Units {
+ for _, u := range s.Units() {
if u.card.Name != "King" {
continue
}
@@ -14,12 +14,12 @@ func KingGame(s *State) []*Player {
foundKings[u.owner] = struct{}{}
}
- if len(foundKings) == len(s.Players) {
+ if len(foundKings) == len(s.Players()) {
return []*Player{}
}
- loosers := make([]*Player, 0, len(s.Players))
- copy(loosers, s.Players)
+ loosers := make([]*Player, 0, len(s.Players()))
+ copy(loosers, s.Players())
for p := range foundKings {
i := slices.Index(loosers, p)
loosers[i] = loosers[len(loosers)-1]
@@ -27,7 +27,7 @@ func KingGame(s *State) []*Player {
}
winners := []*Player{}
- for _, p := range s.Players {
+ for _, p := range s.Players() {
if !slices.Contains(loosers, p) {
winners = append(winners, p)
}