From 1a5fc52bc2f0a8c0d83cbe91046250bc4dec0ca1 Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Sun, 21 Mar 2021 00:12:29 +0100 Subject: [PATCH] 0 wastelands, size bug --- pkg/generator/world.go | 34 ++++++++++++++++++---------------- pkg/web/service.go | 2 +- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/pkg/generator/world.go b/pkg/generator/world.go index 2ca6e47..5d3c6e5 100644 --- a/pkg/generator/world.go +++ b/pkg/generator/world.go @@ -111,27 +111,29 @@ func New(size int, numWastelands int, numMountains int, numRuins int, seed strin // and surround it with 6 more wastelands var wastelands []int - startPos := roll(w.Size-1) + roll(w.Size-1)*w.Size - w.place(WastelandTerritory, startPos) - wastelands = append(wastelands, startPos) + if numWastelands > 0 { + startPos := roll(w.Size-1) + roll(w.Size-1)*w.Size + w.place(WastelandTerritory, startPos) + wastelands = append(wastelands, startPos) - for i := 0; i < numWastelands-1; i++ { - var candidates []int + for i := 0; i < numWastelands-1; i++ { + var candidates []int - // Find all possible candidates (top, left, bottom, right), - // from all already places wastelands, then choose one at - // random and place it. - for _, wl := range wastelands { - for _, free := range w.neighboursOfType(wl, EmptyTerritory) { - if !contains(candidates, free) { - candidates = append(candidates, free) + // Find all possible candidates (top, left, bottom, right), + // from all already places wastelands, then choose one at + // random and place it. + for _, wl := range wastelands { + for _, free := range w.neighboursOfType(wl, EmptyTerritory) { + if !contains(candidates, free) { + candidates = append(candidates, free) + } } } - } - candidate := randomItem(candidates) - w.place(WastelandTerritory, candidate) - wastelands = append(wastelands, candidate) + candidate := randomItem(candidates) + w.place(WastelandTerritory, candidate) + wastelands = append(wastelands, candidate) + } } // Place 5 mountains on free tiles. We need to make sure that diff --git a/pkg/web/service.go b/pkg/web/service.go index 0faebaf..556c396 100644 --- a/pkg/web/service.go +++ b/pkg/web/service.go @@ -33,7 +33,7 @@ func Start(address string, port int) { } func mapHandler(w http.ResponseWriter, req *http.Request) { - size, err := strconv.Atoi(req.URL.Query().Get("size")) + size, err := strconv.Atoi(req.URL.Query().Get("s")) if err != nil { size = 11 }