0

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.

Community
  • 1
  • 1
llrs
  • 3,308
  • 35
  • 68
  • 3
    This question appears to be off-topic because it belongs on http://gamedev.stackexchange.com – jonrsharpe Jan 26 '14 at 11:21
  • @jonrsharpe I have already check it there and it doesn't fit there neither. I ask how I can program it so I think it fits here. But if I don't receive an answer I will try it there – llrs Jan 26 '14 at 11:29
  • 1
    To make this question a better fit here, provide the following: exactly what you want to happen, and exactly what is currently happening (if errors, provide traceback, if unexpected outputs provide inputs, expected outputs, actual outputs). "not very effective" isn't enough information. If you have code that works but needs improving, you could try http://codereview.stackexchange.com – jonrsharpe Jan 26 '14 at 11:32

2 Answers2

1

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.

Pace
  • 41,875
  • 13
  • 113
  • 156
1

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.

amitp
  • 1,195
  • 1
  • 10
  • 10
  • Nice explanation, although I haven't read it in detail. I hope I can understand it and apply. Is it better to apply the noise to correct the random generate map or before generating the map? If it is already answered in your post omit the question ;) Thanks – llrs May 27 '14 at 10:38
  • 1
    I find it works well when you have the random number generate some /properties/ of the map like height or moisture, and then you generate the map using those properties. The properties can be numeric even if the map is not. For example you can generate height, a number, with coherent noise, and then you can choose ranges of heights to be sea, countryside, hill, mountain. Noise first, then map, for these "big" feature. However, you can also make the map first, then add noise, for "small" features like rocks and trees and so on. – amitp May 29 '14 at 17:15