0 wastelands, size bug

This commit is contained in:
Aaron Fischer 2021-03-21 00:12:29 +01:00
parent 3871273730
commit 1a5fc52bc2
2 changed files with 19 additions and 17 deletions

View file

@ -111,27 +111,29 @@ func New(size int, numWastelands int, numMountains int, numRuins int, seed strin
// and surround it with 6 more wastelands // and surround it with 6 more wastelands
var wastelands []int var wastelands []int
startPos := roll(w.Size-1) + roll(w.Size-1)*w.Size if numWastelands > 0 {
w.place(WastelandTerritory, startPos) startPos := roll(w.Size-1) + roll(w.Size-1)*w.Size
wastelands = append(wastelands, startPos) w.place(WastelandTerritory, startPos)
wastelands = append(wastelands, startPos)
for i := 0; i < numWastelands-1; i++ { for i := 0; i < numWastelands-1; i++ {
var candidates []int var candidates []int
// Find all possible candidates (top, left, bottom, right), // Find all possible candidates (top, left, bottom, right),
// from all already places wastelands, then choose one at // from all already places wastelands, then choose one at
// random and place it. // random and place it.
for _, wl := range wastelands { for _, wl := range wastelands {
for _, free := range w.neighboursOfType(wl, EmptyTerritory) { for _, free := range w.neighboursOfType(wl, EmptyTerritory) {
if !contains(candidates, free) { if !contains(candidates, free) {
candidates = append(candidates, free) candidates = append(candidates, free)
}
} }
} }
}
candidate := randomItem(candidates) candidate := randomItem(candidates)
w.place(WastelandTerritory, candidate) w.place(WastelandTerritory, candidate)
wastelands = append(wastelands, candidate) wastelands = append(wastelands, candidate)
}
} }
// Place 5 mountains on free tiles. We need to make sure that // Place 5 mountains on free tiles. We need to make sure that

View file

@ -33,7 +33,7 @@ func Start(address string, port int) {
} }
func mapHandler(w http.ResponseWriter, req *http.Request) { 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 { if err != nil {
size = 11 size = 11
} }