I need some clever and rather simple solution to my problem - province shape generation. Suppose that map is matrix NxM. Each cell is represented by natural number. 0 means that tile does not belong to any province. numbers 1 means that it belongs to province nr 1, nr 2 means that cell belongs to province nr 2... etc.
Consider this map, which is 4x4:
0000
0000
0000
0000
This map represents 16 tiles that do not belong to any province.
This is map containing 1 province:
0010
0111
0100
0000
this is province of size 5, and id = 1. It has no neighbours.
Consider 3 provinces:
1133
2100
2200
2000
So province 1 is neighbour of 2 and 3. Province 3 is only neighbour of 1 and province 2 is only neighbour of 1. There are also 7 not associated tiles.
My problem is: I want to generate k provinces on map NxN. There are also few simple rules:
- there is max size of province and min size of province (for example min = 2, max = 10)
- all tiles of province should be connected (by vertical or horizontal, but not corners)
Example of invalid province (it's not connected):
1100
0000
0011
0000
- there should not be enclaves (province inside province)
- shapes should be random
I was trying to implement it by flood fill modification but it has some disadvantages. I'll be glad to hear some ideas or any help. Map's can be 300x300 with 200 provinces or more so it should be also some clever algorithm.