aboutsummaryrefslogtreecommitdiff
path: root/go/game/winCondition.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-09-08 15:38:07 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2025-09-08 15:41:45 +0200
commita3ca136cd776ff0089dc33e401d1fc474dc17138 (patch)
tree1968a8ff318c7f021e2cc94df5a057eeee39b099 /go/game/winCondition.go
parentee605fa7fa48803756b0c3216afc4bd692ec144a (diff)
downloadmuhqs-game-a3ca136cd776ff0089dc33e401d1fc474dc17138.tar.gz
muhqs-game-a3ca136cd776ff0089dc33e401d1fc474dc17138.zip
support explicitly winning and implement Approach Supremacy!
Diffstat (limited to 'go/game/winCondition.go')
-rw-r--r--go/game/winCondition.go35
1 files changed, 29 insertions, 6 deletions
diff --git a/go/game/winCondition.go b/go/game/winCondition.go
index 67c0190e..0a97330c 100644
--- a/go/game/winCondition.go
+++ b/go/game/winCondition.go
@@ -43,13 +43,18 @@ func BossGame(name string) *winCondition {
return false
})
+ var winners []*Player
if bossFound {
+ if winners = explicitWinners(s); len(winners) > 0 {
+ return winners
+ }
+
return singleConcessionWinner(s)
}
- winners := make([]*Player, 0, len(s.players))
+ // No Boss was found
for _, p := range s.players {
- if p.Name != name && !p.Conceded {
+ if p.Name != name && !p.Conceded && !slices.Contains(winners, p) {
winners = append(winners, p)
}
}
@@ -72,7 +77,12 @@ var KingGame = &winCondition{
foundKings[u.owner] = struct{}{}
}
+ var winners []*Player
if len(foundKings) == len(s.Players()) {
+ if winners = explicitWinners(s); len(winners) > 0 {
+ return winners
+ }
+
return singleConcessionWinner(s)
}
@@ -93,9 +103,8 @@ var KingGame = &winCondition{
return s.Players()
}
- winners := []*Player{}
for _, p := range s.Players() {
- if !slices.Contains(loosers, p) {
+ if !slices.Contains(loosers, p) && !slices.Contains(winners, p) {
winners = append(winners, p)
}
}
@@ -107,9 +116,9 @@ var KingGame = &winCondition{
// DeathMatch returns the players without enemy units.
var DeathMatch = &winCondition{
condition: func(s *LocalState) []*Player {
- winners := []*Player{}
+ winners := explicitWinners(s)
for _, p := range s.players {
- if len(s.EnemyUnits(p)) == 0 {
+ if len(s.EnemyUnits(p)) == 0 && !slices.Contains(winners, p) {
winners = append(winners, p)
}
}
@@ -121,6 +130,7 @@ var DeathMatch = &winCondition{
desc: "Destroy all enemy units",
}
+// singleConcessionWinner returns the player left over after the rest conceded.
func singleConcessionWinner(s *LocalState) []*Player {
var winner *Player
for _, p := range s.players {
@@ -136,3 +146,16 @@ func singleConcessionWinner(s *LocalState) []*Player {
}
return []*Player{winner}
}
+
+// explicitWinners returns the players that explicitly won the game.
+// Winning the game is sometimes possible without fulfilling a maps win condition,
+// but by achieving some external condition (like Approach Supremacy!).
+func explicitWinners(s *LocalState) []*Player {
+ winners := []*Player{}
+ for _, p := range s.players {
+ if p.Won {
+ winners = append(winners, p)
+ }
+ }
+ return winners
+}