diff options
Diffstat (limited to 'go/game/map.go')
| -rw-r--r-- | go/game/map.go | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/go/game/map.go b/go/game/map.go index 5783c9dd..72e17ad4 100644 --- a/go/game/map.go +++ b/go/game/map.go @@ -10,7 +10,6 @@ import ( "os" "path" "strings" - "time" "gopkg.in/yaml.v3" ) @@ -25,8 +24,9 @@ const ( ) type MapYml struct { - Map string `yaml:"map"` - Symbols map[string]string `yaml:"symbols"` + Map string `yaml:"map"` + Symbols map[string]string `yaml:"symbols"` + StartDeckList string `yaml:"start_deck_list"` } func DummyWinCondition(*State) []*Player { @@ -61,10 +61,14 @@ func ParseMap(data []byte) (*Map, error) { m := &Map{[][]Tile{}, mapYml.Symbols, DEFAULT_RESSOURCE_GAIN, DEFAULT_START_DECK, DummyWinCondition} + if mapYml.StartDeckList != "" { + m.StartDeckList = mapYml.StartDeckList + } + rows := strings.Split(mapYml.Map, "\n") for y := 0; y < len(rows); y++ { - m.Tiles = append(m.Tiles, []Tile{}) row := rows[y] + m.Tiles = append(m.Tiles, []Tile{}) for x := 0; x < len(rows[y]); x++ { s := string(row[x]) tile, err := NewTileFromString(mapYml.Symbols[s], Position{x, y}) @@ -107,7 +111,7 @@ func (m *Map) FindNeighbours(x, y int) (left, right, above, below *Tile) { above = &m.Tiles[y-1][x] } - if y < len(m.Tiles) { + if y < len(m.Tiles)-1 { below = &m.Tiles[y+1][x] } @@ -115,7 +119,7 @@ func (m *Map) FindNeighbours(x, y int) (left, right, above, below *Tile) { left = &m.Tiles[y][x-1] } - if x < len(m.Tiles[y]) { + if x < len(m.Tiles[y])-1 { right = &m.Tiles[y][x+1] } @@ -198,7 +202,7 @@ func (m *Map) TileAt(p Position) *Tile { return &m.Tiles[p.Y][p.X] } -func (m *Map) RandomTile(types []TileType) Position { +func (m *Map) RandomTile(r *rand.Rand, types []TileType) Position { candidates := []Position{} for y := 0; y < len(m.Tiles); y++ { for x := 0; x < len(m.Tiles[y]); x++ { @@ -212,12 +216,11 @@ func (m *Map) RandomTile(types []TileType) Position { } } - r := rand.New(rand.NewSource(time.Now().UnixNano())) randIdx := r.Intn(len(candidates)) return candidates[randIdx] } -func (m *Map) RandomTileFromSymbols(symbols []string) (Position, error) { +func (m *Map) RandomTileFromSymbols(r *rand.Rand, symbols []string) (Position, error) { types := make([]TileType, 0, len(symbols)) for _, symbol := range symbols { tileString, ok := m.symbols[symbol] @@ -232,7 +235,7 @@ func (m *Map) RandomTileFromSymbols(symbols []string) (Position, error) { types = append(types, tileType) } - return m.RandomTile(types), nil + return m.RandomTile(r, types), nil } func (m *Map) FilterTiles(filter func(t *Tile) bool) []*Tile { @@ -247,3 +250,7 @@ func (m *Map) FilterTiles(filter func(t *Tile) bool) []*Tile { } return tiles } + +func (m *Map) AllTiles() []*Tile { + return m.FilterTiles(func(*Tile) bool { return true }) +} |
