Jump to content

Using Markov chains for Random Maps beautification


Recommended Posts

This is an idea I've had from reading /r/SubredditSimulator, a subreddit where bots post content using Markov chains. I've been giving it some thinking and I thought I'd share it.
I don't have yet anything to show for it as I'm unable to code at the moment, but might try it later.

The idea is quite simple: let's use some sort of markov Chains to make our random maps nicer. The biggest problems in our random maps, in terms of niceness, is not so much the larger elements (such as continent shape, ...) but the finer details. It just looks too random quite often, compared to scenarios.

My idea is simply to use markov chains to replicate those scenario achievements in random maps.
I won't go into details on markov chains (google it), but basically the idea would be to analyze scenarios of a similar biome (or may only one map, if it's good enough. Fiddling with the data would be needed.), and then use this as a database in a "beautification" pass for random maps.

So RM would still create the maps as we do know, put terrains as we do know, then add basic "necessary" entities, such as trees, player entities, and could also add some larger beautification elements.
Then we'd go into a beautification pass. I see a few ways this could work:

  • For each "important" entity, check what "decoration" entities are usually placed around (from the markov chains) and place those.
  • For each terrain type, check which decoration entities can be found around

Possibly this would require us to "pre-sort" important entities by checking how many important entities they have around (as you might place different stuff around a lone tree than in a forest), but this would have to be checked.

It might be extended to actual terrains too, to make it easier to have nice transitions, but I'm not entirely sure it'd work so well.

Just an idea, anyways.

  • Like 7
Link to comment
Share on other sites

registered for this!

this sounds like a good idea. my exams will be done around the end of july - i will read up about markov chains then and we can take a look at it.

let's study the random gen code together and see what we can come up with. as to training, we'll see. maybe a half -trained markov is better than a non-trained random gen - and if the maps it makes are good, they can be fed to it in return.

  • Like 1
Link to comment
Share on other sites

  • 11 months later...

Works fine, well done! (y)

The main thing missing are the "terrain objects" (see map.js line 292 ++). Most trees are terrain objects as huntable/domesticated animals on many maps.

Distribution is not circular but will do as a start.

I think both the analysis and placement distances should be increased to at least 3 tiles (12m) though the analysis might take quite long with higher distances.

Many actors are placed "under" the entity because of the low distance. Using the squareroot (beautifier.js line 18: randFloat(-1,1) -> Math.pow(randFloat(-1,1), 0.5) ) will reduce such cases.

I didn't print a screenshot because I didn't find a good before/after example, sry.

EDIT: This will definitely become a feature used by most maps!

Link to comment
Share on other sites

I think the amount of actors added is too big (it reminds me of the maps I made in the beginning that ran with ~2 fps because of the amount of actors :P ) Are those deers placed as well? (that might not be wanted from gameplay perspective, as a RMS scripter you want to be sure about the amount of animals added and not rely on some random beautifier placement) 

Link to comment
Share on other sites

FYI, the mod runs the beautification 4 times when it should really just be run one time, to overdo it.

Here are some screenshots from a modded Kerala with no beautification. I added a flag for all added props. As you can see it adds a lot of props, particularly under dense amount of trees.

 

I've also updated the github repo with the latest version of the script and mod. It now takes basic distances into account so the result is overall better.

 

screenshot0004.png

screenshot0005.png

Link to comment
Share on other sites

I don't think a beautification pass like that is really easy to do during the map generation. It might be helped by better integration with the random map generator though.

I've kept the work up, now working on adding more "meta" info. I've also added a function to add a given amount of actors, so you can easily set your density. Results at "2","10" and "100".

screenshot0008.jpg

screenshot0009.jpg

screenshot0010.jpg

  • Like 4
Link to comment
Share on other sites

I've been adding more stuff. First thing is I now open the PMP files, which allowed me to sort which actors go over water and which go under (or both), to avoid weirdness.

I also added the possibility of adding "rules", for example a map might decide to not add entities around a certain fauna/flora element, or forbid some actors from appearing (useful on volcanic lands for example).

Finally I've added a beautifier based on the terrain texture, but it only works on some textures (check out Oasis) so it's not as useful as I'd hoped. It could probably be modified slightly to become a more uniform way of placing actors around a map though.

At this point I'm not entirely sure what to add next, so I invite everyone to play a bit with it and see if they like it. Generally speaking I think it looks good, needs a few tweaks.

 

Just download the mod at https://github.com/wraitii/0-AD-RM-beautifier

 

  • Like 1
Link to comment
Share on other sites

To be a real marcov chain it would  need to have entities and actors in the (square) matrix IMO.

The advantage would be that objects could then be placed continously over any size of area without entities to start with (or only one entity to start with).

The disadvantage would be that also placing entities means less controll of the map designer about resource distribution and ammount

 

So maybe let's just sick with only placing actors and maybe do a full map generation script with real marcov chains (best if also including terrain texture) later.

  • Like 1
Link to comment
Share on other sites

Should be somewhat trivial to adapt to use in skirmish maps as the "script" part, then you could load it up, open the map on Atlas, save it, remove the script. I agree it would be a nifty Atlas tool also, but I don't think Atlas supports running arbitrary JS, so it'd have to be C++, and that would make it much more complicated to implement.

 

As for creating a more complete map using real markov chains, it sounds possible but I think it'd require a different, more "top down" approach.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...