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
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

View file

@ -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
}