Reputation: 3397
I created object, that with random
selects which type of terrain is and which weather it has. That is fine for just one place, but now I want to make it bigger and create a map. I create a matrix with numpy
that contains several terrains, but I don't want it to be random as you can see in the example there is a lake at the side of a sea and it doesn't make sense. How can I create this map to make it seem real?
For example I have this matrix of types of terrain:
[['high mountain' 'high mountain' 'high mountain']
['town' 'town' 'forest']
['house' 'lake' 'sea']]
and this weather:
[['windy' 'sunny' 'cloudy']
['sunny' 'light' 'cloudy']
['light' 'sunny' 'light']]
The possible terrains are: cave, abandoned house, castle, river, forest, house, mountain, high mountain, jungle, desert, sea, lake, town, city, countryside.
And the possible weather are: rainy, sunny, cloudy, stormy, windy, light.
At the moment I create it like that:
map_1=numpy.eye(3, dtype=object)
for i in range(3):
for j in range(3):
map_1[i,j]=Place()
#Where Place it is the object that randomly generates the terrain and the weather
I thought to use this function that I found here:
def weighted_choices(choices, weights):
import random as rdm
total = sum(weights)
treshold = rdm.uniform(0, total)
for k, weight in enumerate(weights):
total -= weight
if total < treshold:
return choices[k]
And after checking the four sides or at least the ones already create, create the new terrain according to the setted preferences of weights (where I could set that Psea=0).
The desired result should take into account which are the type of the surrounding terrains of the one that will be created and act in consonance of which type of terrain and weather it has, using the weighted_choices function or other functions.
[['high mountain' 'high mountain' 'high mountain']
['town' 'town' 'forest']
['house' 'countryside' 'sea']]
and this weather:
[['windy' 'sunny' 'cloudy']
['sunny' 'light' 'cloudy']
['light' 'sunny' 'light']]
What I have tried is to create a random map and then check it manually and substitute the terrains I don't like for others. But I didn't found a way to take into account the surroundings.
Upvotes: 0
Views: 414
Reputation: 1335
You're looking for coherent noise. You want random numbers, but you want them to take into account the surrounding random numbers. For example, if you want to consider how wet/dry an area is, you might have a forest next to grassland, and grassland next to desert, but it's less likely for forest to be next to desret. Another example, if you want to consider the weather, you might have sunny areas next to cloudy areas and cloudy areas next to rainy areas but you may want sunny and rainy to be adjacent rarely.
This page explains coherent noise generation. When I studied this topic (for map generation), I wrote up my notes here.
Upvotes: 1
Reputation: 43867
There are many approaches to random map generation that try and solve the exact problem you are trying to solve. There is no universal answer. Gamedev would be a great place to put your question for a more exhaustive list of possibilities. I will simply answer with a fairly detailed tutorial for one approach that I know of.
Upvotes: 1