0

I want to develop a game where the universe is a maximum 65536 x 65536 grid. I do not want the universe to be random, what I want is for it to be procedurally generated according to location. What it should generate is a number from 0 to 15.

0 means empty space. Most of the universe (probably 50-80%) is empty space.
1 - 9 a planet of that technology level
10-15 various anomalies (black hole, star, etc.)

Given an address from 0x8000-0xFFFF or 0 or 1-0x7fff for the X address, and the same range for the Y address, returns a number from 0 to 15. Presumably this would place planets nearer to 0,0 more plentiful than those at a distance of

The idea being, the function is called passing the two values and returns the planet number. I used to have a function to do this, but it has gotten lost over various moves.

While the board could be that big, considering how easy it would be to get lost, I'll probably cut the size to 1200 in both directions, -600 to +600. Even that would be huge.

I've tried a number of times, but I've come to the conclusion that I lack the sufficient math skills to do this. It's probably no more than 10 lines. As it is intended to be multiplayer, it'll probably be either a PHP application on the back end or a desktop application connecting to a server.

Any help would be appreciated. I can probably read any commonly used programming language you might use.

Paul Robinson

Olivier
  • 13,283
  • 1
  • 8
  • 24
  • Not enough information. You don't even say if you allow 2 planets at neighbor locations. – Olivier Aug 14 '22 at 07:32
  • I understand that you universe is a flat square (2 dimensional) and the center of the universe is at x=0 and Y=0. If the size of the universe is 64Kx64K, then the X and Y range are the same= -32767 to +32767. What your ask is a function which takes two arguments (X and Y coordinates) and return a random number between 0 and 15. Is it right? I don't think you'll get a "nice" universe with that... – fpiette Aug 14 '22 at 08:01
  • 1
    In my opinion, more than 80% of you universe should be empty space. Probably 99.9% should be empty. Or even 99.99%. Depending on realism you want to achieve, you should probably first create the stars with a very low density and the create planets near the stars. It is likely that you need to better describe the wanted universe before going to math. – fpiette Aug 14 '22 at 08:07
  • Generally use a (pseudo-)random number generator and fix the seed. You could either generate the universe and save it (possibly huge, but doable) or use the coordinates for generating the random seed for each position. If the universe should get thinner going away from (0,0) you could use a normal distribution for first deciding, whether the position is empty 0 or filled. Get one such number, take the absolute value, and compare it to a threshold. You should change the threshold with the distance, e.g. abs(random) > 2 + distance / 1000. The 2 would be the initial sparsity around the origin. – Sebastian Aug 14 '22 at 09:09
  • You can do in a similar way deciding, what planet or anomaly there is. Make it a uniform distribution or depending it on the distance. You could also get a random number between 0 and 99 and translate the result 0-19=1, 20-24=2, ... to make some objects more common and others rare. – Sebastian Aug 14 '22 at 09:16
  • @olivier Yes, two planets could be next to each other, or close to each other. This would be useful for certain actions in the game. – Paul Robinson Aug 16 '22 at 21:28
  • @fpiette No, the planet locations are not random. They are supposed to be computed so that if someone travels a few dozen or a few hundred sectors, coming back the universe is the same, all the planet values remain the same. Realism, i.e a realistic depiction of the actual universe is not necessary or desirable. – Paul Robinson Aug 16 '22 at 21:31

1 Answers1

0

See How to draw sky chart? for the planetary position math. Especially pay attention to the image with equations you can use it to compute period of your planet based on its distance and mass to system central mass... for simple circular orbit just match the centripedal force with gravity like I did in here:

Is it possible to make realistic n-body solar system simulation in matter of size and mass?

So for example:

G = 6.67384e-11;
v = sqrt(G*M/a);                           // orbital speed
T = sqrt((4.0*M_PI*M_PI*a*a*a)/(G*(m+M))); // orbital period 
pos = (a,0,0);                             // start position
vel = (0,sqrt(G*M/a),0);                   // start speed

The distribution of planets and their sizes complies specific (empirically obtained) rules (that is one of the reasons why we are still looking for 10th planet). I can't remember the name of the rule, however from quick look on Google Image from here can be used too:

planet distribution

Distribution of the planets in solar system according to their mass and their distances from the Sun. The distances (X-axis) are in AU and masses (Y-axis) in Yotta (10^24)

Jupiter mass is M=1,898e27 kg so mass units are in 10^24 kg.

So just match your PRNG generation to such curve and be done with it.

halfer
  • 19,824
  • 17
  • 99
  • 186
Spektre
  • 49,595
  • 11
  • 110
  • 380