From 926ca5cdd20a39e3e05aaa3486cb166718dab5ca Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Thu, 26 Jan 2023 22:16:10 +0100 Subject: intermeditae commit --- go/game/map.go | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 5 deletions(-) (limited to 'go/game/map.go') diff --git a/go/game/map.go b/go/game/map.go index 72e17ad4..cfabfaf9 100644 --- a/go/game/map.go +++ b/go/game/map.go @@ -19,8 +19,8 @@ const ( BASE_URL string = "localhost:8000/" MAP_URL_PART string = "html/build/maps" - DEFAULT_RESSOURCE_GAIN int = 5 - DEFAULT_START_DECK string = "3 misc/farmer" + DEFAULT_RESOURCE_GAIN int = 5 + DEFAULT_START_DECK string = "3 misc/farmer" ) type MapYml struct { @@ -36,9 +36,10 @@ func DummyWinCondition(*State) []*Player { type Map struct { Tiles [][]Tile symbols map[string]string - RessourceGain int + ResourceGain int StartDeckList string WinCondition func(*State) []*Player + Stores map[Position]*Store } func readMap(r io.Reader) (*Map, error) { @@ -59,7 +60,14 @@ func ParseMap(data []byte) (*Map, error) { mapYml.Symbols[" "] = "neutral" - m := &Map{[][]Tile{}, mapYml.Symbols, DEFAULT_RESSOURCE_GAIN, DEFAULT_START_DECK, DummyWinCondition} + m := &Map{ + Tiles: [][]Tile{}, + symbols: mapYml.Symbols, + ResourceGain: DEFAULT_RESOURCE_GAIN, + StartDeckList: DEFAULT_START_DECK, + WinCondition: DummyWinCondition, + Stores: make(map[Position]*Store), + } if mapYml.StartDeckList != "" { m.StartDeckList = mapYml.StartDeckList @@ -70,11 +78,17 @@ func ParseMap(data []byte) (*Map, error) { row := rows[y] m.Tiles = append(m.Tiles, []Tile{}) for x := 0; x < len(rows[y]); x++ { + pos := Position{x, y} s := string(row[x]) - tile, err := NewTileFromString(mapYml.Symbols[s], Position{x, y}) + tile, err := NewTileFromString(mapYml.Symbols[s], pos) if err != nil { return nil, err } + + if tile.Type == TileTypes.Store { + m.Stores[pos] = NewStore() + } + m.Tiles[y] = append(m.Tiles[y], tile) } } @@ -254,3 +268,36 @@ func (m *Map) FilterTiles(filter func(t *Tile) bool) []*Tile { func (m *Map) AllTiles() []*Tile { return m.FilterTiles(func(*Tile) bool { return true }) } + +func (m *Map) distributeStoreCards(cards PileOfCards, rand *rand.Rand) { + nStores := len(m.Stores) + stores := make([]*Store, 0, nStores) + for _, store := range m.Stores { + stores = append(stores, store) + } + + d := NewDeckFrom(cards) + d.Shuffle(rand) + nCards := d.Size() + + for i := 0; i < nCards; i++ { + c := d.DrawOne() + stores[i%nStores].AddCard(c) + } +} + +func (m *Map) redistributeStoreCards(cards PileOfCards, rand *rand.Rand) { + poc := NewPileOfCards() + for _, store := range m.Stores { + store.MoveInto(poc) + } + m.distributeStoreCards(poc, rand) +} + +func (m *Map) HasStores() bool { + return len(m.Stores) > 0 +} + +func (m *Map) GetStoreOn(p Position) *Store { + return m.Stores[p] +} -- cgit v1.2.3