aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-07-19 18:44:19 -0400
committerFlorian Fischer <florian.fischer@muhq.space>2025-07-22 12:54:28 -0400
commit2c3f1c03d84495af6df5070031deb013d3b20bc4 (patch)
treea03ebc5008c555948d8f60fe6dc56c7e1dadcc00
parent93950ac635d638dd565307c24f0538595ad694fe (diff)
downloadmuhqs-game-2c3f1c03d84495af6df5070031deb013d3b20bc4.tar.gz
muhqs-game-2c3f1c03d84495af6df5070031deb013d3b20bc4.zip
fix king map preparation
-rw-r--r--go/game/map.go17
-rw-r--r--go/game/map_test.go4
-rw-r--r--go/game/permanent.go3
-rw-r--r--go/game/pos.go11
-rw-r--r--go/game/state.go4
-rw-r--r--maps/2P-ring-street.yml4
-rw-r--r--maps/2P-river-king.yml4
7 files changed, 33 insertions, 14 deletions
diff --git a/go/game/map.go b/go/game/map.go
index b3203bd4..54071933 100644
--- a/go/game/map.go
+++ b/go/game/map.go
@@ -28,7 +28,7 @@ type MapYml struct {
Map string `yaml:"map"`
Symbols map[string]string `yaml:"symbols"`
StartDeckList string `yaml:"start_deck_list"`
- Kings [][]int `yaml:"omitemptt"`
+ Kings [][]int `yaml:"kings,omitempty"`
}
type Map struct {
@@ -95,13 +95,16 @@ func ParseMap(data []byte) (*Map, error) {
m.selectStreets()
- if len(mapYml.Kings) == 0 {
+ if len(mapYml.Kings) > 0 {
m.WinCondition = KingGame
m.Prepare = func(s *LocalState) {
- k := NewCard("misc/king")
for i, kingPos := range mapYml.Kings {
- p := s.PlayerById(i + 1)
- s.addNewUnit(k, Position{kingPos[0], kingPos[1]}, p)
+ card := NewCard("misc/king")
+ owner := s.PlayerById(i + 1)
+ // TODO: Fix position index base.
+ pos := Position{kingPos[0] - 1, kingPos[1] - 1}
+ log.Println(card, pos, owner)
+ s.addNewUnit(card, pos, owner)
}
}
}
@@ -210,9 +213,9 @@ func LoadMap(path string) (*Map, error) {
}
// TileAt returns the tile at a certain position.
-// Id p is an invalid position, nil is returned.
+// If p is an invalid position, nil is returned.
func (m *Map) TileAt(p Position) *Tile {
- if p.Y < 0 || p.Y >= len(m.Tiles) || p.X < 0 || p.X >= len(m.Tiles[p.Y]) {
+ if !p.Valid() || p.Y >= len(m.Tiles) || p.X >= len(m.Tiles[p.Y]) {
return nil
}
return &m.Tiles[p.Y][p.X]
diff --git a/go/game/map_test.go b/go/game/map_test.go
index e950747b..15fa05cb 100644
--- a/go/game/map_test.go
+++ b/go/game/map_test.go
@@ -52,8 +52,8 @@ symbols:
2: spawn player 2
kings:
- - (1,9)
- - (9,1)`
+ - [1,9]
+ - [9,1]`
m := parseMapString(t, s)
diff --git a/go/game/permanent.go b/go/game/permanent.go
index 47166d61..76f2325d 100644
--- a/go/game/permanent.go
+++ b/go/game/permanent.go
@@ -60,6 +60,9 @@ type permanentBase struct {
}
func newPermanentBase(card *Card, tile *Tile, owner *Player) permanentBase {
+ if card == nil || tile == nil || owner == nil {
+ log.Panicf("invalid argument for newPermanentBase(%p, %p, %p\n)", card, tile, owner)
+ }
if tile != nil && tile.Permanent != nil {
log.Panicf("Tile at %v already occupied by %v", tile.Position, tile.Permanent)
}
diff --git a/go/game/pos.go b/go/game/pos.go
index 133f599b..bf35ca3b 100644
--- a/go/game/pos.go
+++ b/go/game/pos.go
@@ -4,6 +4,12 @@ import (
"fmt"
)
+// Position represents a zero-based position on the map.
+// TODO: Change to a 1-based coordinate system.
+//
+// This allows to use the zero value as invalid Position.
+//
+// The origin is the upper left corner of the map.
type Position struct {
X int
Y int
@@ -22,3 +28,8 @@ func (p Position) String() string {
func INVALID_POSITION() Position {
return Position{-1, -1}
}
+
+// Valid reports if a coordinate is smaller than 0.
+func (p Position) Valid() bool {
+ return p.X >= 0 && p.Y >= 0
+}
diff --git a/go/game/state.go b/go/game/state.go
index 6c3b237f..e16233a5 100644
--- a/go/game/state.go
+++ b/go/game/state.go
@@ -137,7 +137,9 @@ func (s *LocalState) IsActivePlayer(p *Player) bool {
func (s *LocalState) Loop() []*Player {
// Prepare the map
- s._map.Prepare(s)
+ if s._map.Prepare != nil {
+ s._map.Prepare(s)
+ }
if s._map.HasStores() {
poc := NewPileOfCards()
diff --git a/maps/2P-ring-street.yml b/maps/2P-ring-street.yml
index 18dd5328..e0ff41ae 100644
--- a/maps/2P-ring-street.yml
+++ b/maps/2P-ring-street.yml
@@ -18,5 +18,5 @@ symbols:
2: spawn player 2
kings:
- - (1,9)
- - (9,1)
+ - [1,9]
+ - [9,1]
diff --git a/maps/2P-river-king.yml b/maps/2P-river-king.yml
index 5ef0cca8..45356715 100644
--- a/maps/2P-river-king.yml
+++ b/maps/2P-river-king.yml
@@ -20,5 +20,5 @@ symbols:
2: spawn player 2
kings:
- - (1,11)
- - (11,1)
+ - [1,11]
+ - [11,1]