AmazonPython
AmazonPython

Reputation: 1

Algorithm for even distribution on a 2d matrix

Here is my problem:

I have a int[,] object (a 2d array of integers) full of 0's of size N^2. This is the base for my game's map.M

Now I need to take this array and with the following parameters: separationDistance andnumberOfIslands, I need to put numberOfIslands number of 1's at pseudo-random indexes in the array so that:

  1. each 1 is AT LEAST separationDistance away from any other 1, and
  2. all 1's are evenly distributed throughout the array.

The 0's are gonna be water, and the 1's are the "anchors" for each island.

Does anyone know an algorithm that would be applicable here?

Initially I thought that the perlin noise algorithm would be the perfect tool for the job, but as I took the ticket and actually got to work, I quickly realised it's not at all what I need at this stage.

Upvotes: 0

Views: 30

Answers (1)

AmazonPython
AmazonPython

Reputation: 1

To anyone else with the same problem; I found the following algorithms that seem to be exactly what I'm looking for:

  • Poisson Disk Sampling Algorithm
  • Bridson’s Algorithm

Upvotes: 0

Related Questions