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.