数学问题:星系的程序生成

发布于 2024-07-11 01:07:53 字数 349 浏览 8 评论 0原文

我将制作一个完全按程序生成的空间/交易/战斗游戏。 但是,我知道将整个星系的所有细节存储在内存中是不可行的。 因此,我一直认为我可以使用种子来生成太阳系,并且从该太阳系,您可以使用跳跃门前往其他太阳系。 问题是,如果我从起始太阳系跳转到另一个太阳系,我需要能够回到具有完全相同特征(行星、小行星等)的完全相同的起始太阳系。

本质上,我需要能够从一个数字生成整个星系。 从生成一个太阳系的那个数字中,我需要能够生成与第一个太阳系链接的所有其他太阳系以及与这些太阳系链接的所有太阳系,依此类推。 如果我回到它们的话,每个太阳系都必须保持完全相同的特征。 此外,每个太阳系的链接数量可以是随机的,也可以是固定的,由您选择。 不过随机的会更好。

I'm going to make a space/trading/combat game that is completely procedurally generated. But, I know that storing all of the details of the whole galaxy in memory is unfeasable. As a result, I've been think that I can use a seed to generate a solar system, and from that solar system, you can use jumpgates to travel to other solar systems. The problem is that if I jump to another solar system from the starting one, I need to be able to get back to the exact same starting solar system with the exact the same features (planets, asteroids, etc.).

Essentially, I need to be able to generate a whole galaxy from one number. And from that one number, which generates one solar system, I need to be able to generate all of the other solar systems that link from the first one and all of the solar systems that link from those, and so on. And each solar system has to stay exactly the same feature-wise, if I return to them. Also, the number of links from each solar system can be either random, or fixed, your choice. Random would be better though.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(19

风筝有风,海豚有海 2024-07-18 01:07:53

如果你觉得自己很勇敢,你可以比看看 Ian Bell 是如何做到的更糟糕 适用于 Elite 的原始版本

If you're feeling brave, you could do worse than look at how Ian Bell did it for the original version of Elite

星星的轨迹 2024-07-18 01:07:53

这是我理解的基本想法。 假设你已经到达了 42 号恒星系统,你需要找出里面有什么。 它有 nplanet 行星 - 0 到 10 之间的数字,比如说:

>>> star_system = 42
>>> nplanets = hash('nplanets%d' % star_system) % (10 + 1)
>>> nplanets
4

好的,那么对于 2 号行星,游戏开始时有多少个空间站在轨道上? 找出 0 到 3 之间的数字:

>>> planet = 2
>>> nstations = hash('nstations%d/%d' % (star_system, planet)) % (3 + 1)
>>> nstations
1

以此类推。 每个数字都是索引(在本例中为#42 恒星系统,#2 行星)的哈希函数,并缩小到适当的范围。 由于哈希函数是确定性但“随机”的,因此每次都是相同的,但对玩家来说是随机的。

当然,对具有长序列(如“nstations”)的字符串进行哈希处理并不是最快的方法,但它展示了这个想法。

Here's the basic idea as I understand it. Say you've arrived in star system #42 and you need to find out what's in it. It has nplanets planets -- a number between 0 and 10, say:

>>> star_system = 42
>>> nplanets = hash('nplanets%d' % star_system) % (10 + 1)
>>> nplanets
4

OK, so over by planet #2, how many space stations are in orbit there at the start of the game? Find a number between 0 and 3:

>>> planet = 2
>>> nstations = hash('nstations%d/%d' % (star_system, planet)) % (3 + 1)
>>> nstations
1

And so on. The numbers are each a hash function of the indices (star system #42, planet #2, in this case), reduced to the appropriate range. Since hash functions are deterministic but 'random', it's the same each time, but random-looking to the player.

Of course, hashing strings with long sequences like 'nstations' in them isn't the fastest possible way to go about it, but it shows the idea.

凶凌 2024-07-18 01:07:53

看看原始的百战天虫游戏。
我认为它声称有大约 40 亿个可能的级别。
每个级别都是基于大约 20 个字符的短种子字符串生成的。
这决定了

  • 关卡的主题(北极、森林等)、
  • 景观的形状、
  • 地面的光滑程度、
  • 预建关卡细节的放置(雪人、岩石……)、
  • 蠕虫、地雷团队的放置和武器箱。

如果您喜欢某个关卡,您可以写下种子字符串,并在以后使用它来重新生成相同的关卡。

这是一个非常复杂但确定性函数的示例,具有单个输入参数。 我认为这是您所需要的基本概念。

Take a look at the original Worms game.
I think it claimed to have about 4 billion possible levels.
Each level was generated based on short seed string of maybe 20 characters.
This determined

  • the theme of the level (arctic, forest, etc...)
  • the shape of the landscape
  • the slipperiness of the ground
  • the placement of prebuilt level details (snowmen, rocks...)
  • the placement of your team of worms, landmines and weapon crates.

If you enjoyed a level, you could write down the seed string, and use it to regenerate the same level at a later date.

This is an example of a very complex, but deterministic function, with a single input parameter. I think this is the essential concept of what you need.

作死小能手 2024-07-18 01:07:53

你不能只对星系 ID 进行 SHA1,例如:

Galaxy 1

Sha1(1) = 356a192b7913b04c54574d18c28d46e6395428ab

Galaxy 2

Sha1(2) = da4b9237bacccdf19c0760cab7aec4a8359010b0

Galaxy 3

Sha1(3) = 77de68daecd823babbb58edb1c8e14d7106e83bb

然后你可以对代码进行分段,即:

前 4 个字符 = 行星数量

356a
da4b
77de

你需要某种字符串到数字的算法,一个简单的算法是获取每个非数字字符的 ASCII 代码,然后将它们全部相乘或执行其他操作。

现在我们知道银河系中有多少颗行星,银河系的 x、y、z 维度又如何呢?

接下来的 9 个字符 = Galaxy Dimensions (x,y,z)

原理同上,将代码变成一个大数。 还要进行一些敏感性检查,您不会想要一个 10 英里 x 10 英里 x 10 英里、其中有 2000 万颗行星的星系。 采用某种加权算法,例如最小大小是行星数 * 10000。您需要使用数字来确保范围全部兼容,并且从哈希中选择的字符实际上为您提供了合理的范围。

或者,您可以使用随机数在星系的最小和最大大小之间选择一个数字,但使用恒定的 RNG 种子,例如星系 ID! 这样,星系的大小对于观察者来说基本上是“随机的”,但每次都是相同的。

等等等等!

这是获取宇宙属性的一种方法,但是行星属性又如何呢? 比如人口和其他东西?

如果您的 Galaxy 1 有 20,000 个行星,您可以这样做:

Sha1('1:340') = bc02ab36f163baee2a04cebaed8b141505cc26b5

即 Galaxy 1,行星 340。然后您可以随意拼接该代码。 使用哈希的好处是每个星球都应该有一个完全唯一的代码。

Can't you just SHA1 the galaxy ID, EG:

Galaxy 1

Sha1(1) = 356a192b7913b04c54574d18c28d46e6395428ab

Galaxy 2

Sha1(2) = da4b9237bacccdf19c0760cab7aec4a8359010b0

Galaxy 3

Sha1(3) = 77de68daecd823babbb58edb1c8e14d7106e83bb

You can then segment the code, IE:

First 4 Chars = Number of planets

356a
da4b
77de

You would need some sort of string to number algorithm, one simple one would be to take the ASCII code of every non numeric character, and then multiply them all together or something.

So now we know how many planets are in our galaxy, how about galaxy x,y,z dimensions?

Next 9 chars = Galaxy Dimensions (x,y,z)

Same principle as above, turn the code into a large number. Have some sensibility checks as well, you don't want a galaxy thats 10milesx10milesx10miles with 20 million planets in it. Have some sort of weighted algorithm, like minimum size is # of planets * 10000. You will need to play with the numbers to make sure the ranges are all compatible and the selected chars from the hash actually give you a reasonable range.

Or, instead of this, you can have a random number pick a number between the min and max size of the galaxy, but use a constant RNG seed, such as the galaxy ID! This way the galaxy sizes are essentially 'random' for the observer, but they will be the same every time.

Etc etc!

That's one way of getting properties of your Universe, but what about planet properties? Like population and other stuff?

If you have Galaxy 1 with 20,000 planets, you can do:

Sha1('1:340') = bc02ab36f163baee2a04cebaed8b141505cc26b5

That is, galaxy one, planet 340. You can then just splice up that code however you want. The benefit of using a hash is that every planet should have a totally unique code.

心房的律动 2024-07-18 01:07:53

我认为值得注意的是,

  1. 为相同输入产生相同随机输出的生成器称为伪随机数生成器,“PRNG”。 通常,您在一开始就给它一个“种子”输入数字,然后从中提取随机数字,调用它而无需进一步输入。 注意:您无法“返回”到较早的数字,至少不能从头开始。

  2. 使用坐标作为每次调用的输入来调用的类似 PRNG 的函数通常是“噪声”函数。 在这里,您不会遇到“无法返回”的问题 - 只需再次使用“较早的”输入进行调用即可。
    噪声函数使用 PRNG(作为后端;或者至少可以),它仍然可以在一开始就播种,因此您不会失去“单一数字中的宇宙”功能。

  3. 虽然您每次都可以使用 PRNG 并将星系坐标组合到“种子”中,但最多只能得到“白噪声”,而没有其他属性。 噪声函数更适合这项工作,因为可以选择甚至调整它来为您提供可平铺/平滑/螺旋状的外观/等。 结果。
    例如,搜索使用柏林噪声制作的纹理图像。
    我希望您看到,使用相同的噪声函数,您可以创建例如数千个随机云,但是通过根据您的需要(不仅仅是种子或坐标)调整噪声函数,您可能会得到熔岩或星系。 不过,调整它可能并不简单。

  4. 每次调用的输入坐标数量决定了噪声函数的维数,因此对于二维贴图(或纹理等),您可以使用二维噪声函数。 然后你每次都像noise2d(x,y)一样调用它。

在你的情况下,我会尝试使用 3 维单纯形噪声函数(单纯形来自柏林噪声的作者,推荐为更好)。

然后,每个恒星系统坐标三元组都会为您提供一个结果编号。 下一个决定是:这个数字代表什么? 为了充分利用单纯形噪声的平滑功能,我会将较低的数字映射到更空的太阳系,将较高的数字映射到质量更大的系统。
或者,也许更好的是,对于每个系统,使用子坐标多次调用单纯形噪声。 中等大小的结果数字是行星,小数字是真空或小行星。 大数字明星等。

该主题不活跃并且很旧,但搜索可能会在这里结束,就像我的那样。

I think it is worth noting, that

  1. a generator that produces the same random-looking output for the same input is called a pseudo random number generator, "PRNG". Typically you give it one "seed" input number at the very beginning and then just pull random numbers from it, calling it without further input. Note: you cannot "go back" to an earlier number, at least not without starting at the beginning.

  2. a PRNG-like function that is called with coordinates as input of each call is typically a "noise" function. Here you do NOT have the "cannot go back" problem - just call with the "earlier" input again.
    A noise function uses a PRNG (as a backend; or at least it could) which still can be seeded at the very start, so you do not lose your "universe out of one number" feature.

  3. While you could just use a PRNG and combine the galaxy coordinates to a "seed" each time, you would only get "white noise" at best, with no further attributes. A noise function is a much better fit for the job, as it can be chosen or even adjusted to give you tileable/smoothed/spiral-like looking/etc. results.
    For examples search texture images that were made using perlin noise.
    I expect you to see that with the same noise function you may create e.g. thousands of random clouds, but by adjusting the noise function to your needs (not just the seed or coordinates), you may get lava or galaxies instead. Adjusting it may not be trivial though.

  4. The number of input coordinates for each call determines the number of dimensions of the noise function, so for a two dimensional map (or texture etc.) you could use a 2-dimensional noise function. Then you call it like noise2d(x,y) each time.

In your situation I would try a 3-dimensional simplex noise function (simplex is from the author of perlin noise, recommended as being better).

Each star system coordinate-triplet then gives you one result number. Next decision would be: what does the number represent? To put the smoothing feature of the simplex noise to good use, I would map lower numbers to emptier solar systems and higher numbers to systems with more mass.
Or, maybe better, for each system call simplex noise multiple times with sub-coordinates. Medium sized result numbers then are planets, small numbers are vacuum or asteroids. Big numbers stars, etc.

The topic is not active and it is old but searches may end up here, as mine did.

梦年海沫深 2024-07-18 01:07:53

每个太阳系的随机种子是一个可行的解决方案,但我有一种感觉,你在这里找错了树。

玩家可以做任何事情来改变那里的东西吗? (比如说,建造一些东西,开采耗尽的资源等等?)如果是这样,你无论如何都必须保存状态。

玩家是否可以在不必实际返回那里的情况下查看该地点的情况? (如果他不能,为什么不呢?!)你会去查找它,还是会重新生成整个太阳系只是为了找出有关它的一条信息? (PRNG 解决方案不允许您仅获得太阳系的一部分,您必须制作整个系统。)

究竟有多少细节需要保存?

A random seed for each solar system is a viable solution but I have a feeling you're barking up the wrong tree here.

Can the player do anything to change what's there? (Say, build something, mine a depleatable resource etc?) If so, you'll have to save the state anyway.

Can the player look up what the place was like without actually having to go back there? (And if he can't, why not?!) Are you going to look it up or are you going to regenerate the entire solar system just to find out a piece of information about it? (the PRNG solution doesn't permit you to obtain only part of the solar system, you have to make the whole thing.)

Just how much detail is there anyway that you need to save?

征棹 2024-07-18 01:07:53

我认为“星系”中真的没有那么多信息无法存储在当今的计算机上。 假设一个星系有 100 颗恒星,每颗恒星有 10 颗行星,每颗行星有 3 个卫星。 您必须跟踪 100 颗恒星 + 1,000 个行星 + 3,000 个卫星,即 4,100 个天体。

以下是我们可能想要跟踪行星的事情。

大量的
X、Y、Z 位置
一天的长度(绕其自身轴旋转的时间)
年份长度
人口
50 个不同资源的资源量

假设每个值都需要一个 double 来存储它,并且我们有 57 个值要存储(让我们四舍五入为 100),那么我们就有 100 个值 * 8 个字节 * 4100 个主体 = 3,280,000 个字节。 现在,这是 3 兆数据。 这可能看起来很多,但实际上并没有那么多。 另外,我不认为你真的想在一个星系中拥有这么多恒星。 游戏确实太大而无法探索,并且可能会变得难以管理,无法尝试实际模拟给定星系中正在发生的所有事情。

这么看吧。 如果您使用像《模拟城市》这样的游戏,将城市网格上的每个方块视为潜在的行星,然后您就会意识到一个小文件中可以存储多少信息,这样您就不必随机生成任何内容。

I don't think there is really all that much information in a "galaxy" that you couldn't store it on today's computers. Let's assume a galaxy has 100 stars, and that each star has 10 planets, and that each planet has 3 moons. That's 100 stars + 1,000 planets + 3,000 moons you have to keep track of, which is 4,100 bodies.

Here's the things we may want to keep track of for a planet.

Mass
X,Y,Z position
Length of day (time to rotate on it's own axis)
Length of year
Population
Amount of resources for 50 different resources

Assuming each value requires a double to store it, and we have 57 values to store (lets round it up and say 100), then we have 100 values * 8 bytes * 4100 bodies = 3,280,000 bytes. Now, thats 3 megs of data. That may seem like a lot but it's really not that much. Also, I don't think that you'd really want to have so many stars in a single galaxy. The game would really be just too big to explore, and would probably get unmanageable large to try to actually simulate all the stuff that's going on in a given galaxy.

Look at it this way. If you take a game like SimCity, and look at each square on the city grid as a potential planet, and then you realize just how much information can be stored in a small file, so that you don't have to randomly generate anything.

情泪▽动烟 2024-07-18 01:07:53

我使用梅森旋转器。 PRNG 接受任意长度的种子数组。
例如,我想在坐标 x=25,y=72 上生成星系。 我用种子重新初始化了twister [25,72]。
如果我想在这个星系中生成第 1138 颗行星,我使用 [25,72,1138]。
国家? [25,72,1138,10]
城市? [25,72,1138,10,32]
等等。
通过这种方法,您只需使用一个数字(x 坐标之前的数字,在我们的例子中是 25 之前)就可以生成数十亿、数万亿个对象。
现在有一些项目正在使用它。
Noctis:anynowhere.com/
无限宇宙:http://www.infiniverse-game.com/

I use the Mersenne Twister. It is PRNG that accepts as its seed array of any length.
For example, I want to generate galaxy on coordinates x=25,y=72. I re-init twister with seeds [25,72].
If I want to generate 1138th planet in this galaxy, I use [25,72,1138].
Country? [25,72,1138,10]
City? [25,72,1138,10,32]
and so on.
With this method you can generate billions of trillions of zillions of objects using just one number (the one before x coordinate, in our case before 25).
There are some projects now that use it.
Noctis: anynowhere.com/
Infiniverse: http://www.infiniverse-game.com/

许仙没带伞 2024-07-18 01:07:53

假设你从一个星系种子开始,即1234,取这个种子,并生成10000个随机数,每个随机数代表一个恒星系统。 当您接近星星时,您会获取星星的随机数,并将其作为新随机函数的种子。 为围绕恒星运行的天体数量生成一个随机数,并为每个天体生成一个数字(始终使用第二个随机函数),依此类推。
我不知道这是否对您有帮助,但您需要记住,随机函数内部是混乱的,对于初始条件,整个函数都会发生变化。

星系中恒星的种子必须始终产生相同的恒星,恒星的种子必须产生相同的天体,等等。

您始终可以使用统计、密度计算、改进结果来使事情变得更有趣。 始终检查函数对于相同的输入是否会产生相同的结果。

抱歉,如果我的英语很糟糕,我来自阿根廷,英语不是我训练有素的素质之一:p

PD:我正在做同样类型的游戏;)

Suppose you start with a seed for the galaxy, i.e. 1234, take this seed, and generate 10000 random numbers, each one represents a star system. When you approach the star, you take the star's random number, and you it as a seed for a new random function. Generate a random number for the quantity of celestial bodies orbiting the star, and the generate one number for each body (always using the second random function)and so on.
I dont know if this helps you, but you need to remember that the random functions, are internally chaotic, for a initial condition, the whole function changes.

The seed for the stars in the galaxy must produce always the same stars, the seed of the stars must produce the same bodies, etc.

You can always turn things more interesting using statistics, density calculations, improving the results. Check always that the functions will produce the same result for the same input.

Sorry if my english sucks, i'm from Argentina, and english language is not one of my trained qualities :p

PD: I'm doing the same type of game ;)

冷︶言冷语的世界 2024-07-18 01:07:53

您可以从某个种子(“母数”)构建一个 N 位的伪随机数。 然后,您将数字分组并用它们来回答您的问题。

示例:N=20

-> 一位数字:有多少个额外的跳跃门?
-> 三位数:用于生成每个可用跳跃的相应长度的种子
-> 六位数字:产生这个太阳系的种子
-> 十位数字:种子,用于为每个链接的太阳系生成新的 20 位数字种子

然后递归。 每个系统(具有稳定轨道等)都会在时间 0 生成,您必须计算它现在的样子。

当然,这种从母系统开始的方法意味着当前系统距离母系统越远,生成数据所需的时间就越长。 另外,这种方式会形成一棵树,而不是一张网(我希望如此)。

我认为生成坐标会更好 - 在平面中使用极坐标,也许在三维空间中使用椭球体。

You could build a pseudo random number of N digits from a certain seed (the "mother number"). Then, you divide the digits into groups and use them for answering your questions.

Example: N=20

-> one digit: how many additional jump gates?
-> three digits: seed for generating the respective lengths of each available jump
-> six digits: seed for generating this solar system
-> ten digits: seed for generating a new 20 digit seed for each linked solar system

Then recurse. Each system (with stable orbits etc.) gets generated at time 0, and you will have to calculate how it looks now.

Of course, this approach, starting from a mother system, would mean that the farther the current system is from the mother system, the longer it takes to generate its data. Also, this way makes a tree, not a net (which I would expect).

I think that it would be better to generate coordinates - use polar coordinates in the plane, and perhaps an ellipsoid in three dimensions.

痴情换悲伤 2024-07-18 01:07:53

我依稀记得以前做过这样的事。 在 90 年代初期,分形非常流行,我记得有一家公司向游戏程序员提供世界。 他们创造了一个充满星系、太阳和行星的无限宇宙,甚至包括行星上的山谷和纹理。 他们为游戏开发商寻找合适的虚拟房地产。 游戏开发人员将获得软件来渲染和使用它,以及他们在这个分形宇宙中的属性的精确坐标。

我已经用谷歌搜索了几分钟“分形游戏世界行星宇宙”之类的东西,但还没有找到它们。 可能是Pandromeda,但我不太记得了。

为了这个想法,你应该研究分形。 您所需要的只是一个连续的数字字段,您可以从种子中重新创建它,然后将这些数字表示为具有不同属性的恒星、行星和卫星。

I can vaguely recall this being done before. During the early 90's fractals were all the rage and I remember one company offering worlds to game programmers. The had created a whole infinite universe full of galaxies with suns and planets, event down to the valleys and textures of places on the planets. They were offering to find suitable virtual real estate to game developers. The game developers would get the software to render and use this, together with the exact coordinates to their propery in this fractal universe.

I've googled for a few minutes for "fractal game world planet universe" and such, but haven't found them. It might have been Pandromeda, but I can't quite remember.

You should study fractals for this idea. All you need is a continous field of numbers that you can recreate from a seed and then present those numbers as stars, planets and satellites with different properties.

万劫不复 2024-07-18 01:07:53

如果您真的想返回到固定状态,我认为从单个值进行程序生成不是正确的方法。

假设,每个平面都有一个由 256x256 系统组成的固定网格,宇宙中有 16 个平面。 每架飞机最多有 512 个交易站和最多 8 个与其他飞机的链接。 所有交易站和链接都位于固定位置。
您的初始种子值必须至少为 2^76 才能对所有可能的宇宙进行编码。
添加更多的物体(行星、船舶……),数量会呈指数级增长。

编辑:
如果您不允许每个系统中存在多个交易站或链接,则费用会少一些。
我会使用一些永久存储,可能是像 Firebird 或 sqlite 这样的嵌入式数据库。 顺便说一句,我目前正在开发这样的游戏。

If you really want to return to a fixed state, i don't think procedural generation from a single value is the right way to go.

Let's assume, you have a fixed grid of 256x256 systems in each plane and 16 planes in the universe. Each plane has up to 512 trading stations and up to 8 links to other planes. All trading stations and links are on a fixed position.
Your initial seed value has to be at least 2^76 to encode all possible universes.
Add some more objects (planets, ships,...) and the number grows exponentially.

Edit:
It's a bit less if you don't allow more than one trading station or link in each system.
I'd use some permanent storage, maybe an embedded database like Firebird or sqlite. Incidentally i'm currently developing such a game.

如果没有 2024-07-18 01:07:53

这就是我的想法。 不知道这是否是最终版本。

想象一个六边形网格,每个顶点都有一个太阳系。 由于我们处于六边形网格上,因此从任何顶点出发只有三条线。 一个始终是水平的,另外两个是对角线的。 如果我们给起始种子取值为n,那么我们可以给与起始点水平连接的太阳系取值n+1,其他取值n+2和n-2。

噢,糟糕。 我们不一定会得到一个网格。 该死的。 让我们再试一次。

Here's what I have come up with. Dunno if it will be the final version though.

Imagine a hexagonal grid, and at each vertex, a solar system. Since, we're on a hexagonal grid, there are only three lines going from any vertex. One is always horizontal, and the other two are diagonals. If we give the starting seed a value of n, we can give the solar system that is horizontally connected to the starting point a value of n+1, the others get values of n+2 and n-2.

Oh crap. We wont necessarily get a grid. Damnit. Lets try again.

初心未许 2024-07-18 01:07:53

如果您使用伪随机数生成器,则可以保证生成的每个随机数将按照给定种子的相同顺序出现。
每次生成由给定数字生成种子的系统的代码都会显示相同的代码。

使用伪随机数流中的第一个数字来生成“门”的数量。
通过每个门并从数字流中获取一个值以分配给每个目标系统并为其播种。

基于该种子生成每个系统的特征。

有几种已知的用于生成随机种子的算法。

尝试一下梅森扭曲器

If you use a pseudo random number generator, you can guarantee that each random number you generate will appear in the same order from a given seed.
The code to generate a system seeded by a given number will appear the same each time you generate it.

Use the first number from the pseudo random number stream to generate the number of "gates".
Go through each gate and get a value from the number stream to assign to and seed each target system.

Generate the featurs of each system based on that seed.

There are several known algorithms for generating random seeds.

Give the Mersenne twister a crack

丑疤怪 2024-07-18 01:07:53

只要您使用相同的种子调用 srandom(),您就会从 random() 中获得相同的值。 因此,只需将星型系统中的所有内容都建立在对 srandom() 的一次调用之上...然后,您只需要为整个星型系统存储 1 个整数(种子)。 现在这就是压缩!

As long as you call srandom() with the same seed, you'll get the same values out of random(). So, just base everything in a star system off a single call to srandom()... Then, you'll only need to store 1 integer (the seed) for a whole star system. Now thats compression!

眼泪淡了忧伤 2024-07-18 01:07:53

这是我的第二个改进的解决方案。 玩家将从随机生成的太阳系开始。 每个系统都连接到 1 到 4 个其他系统。 将它们视为北、南、东、西系统。 如果玩家要通过北跳跃门,他将被带到一个种子比之前的系统多一个的系统。 如果他南下,该系统的种子就会少一个。 2+ 和 2- 分别代表东和西。 到这些系统的距离(以秒差距或光年或其他单位为单位)是根据系统的种子和您到达的方向来计算的。 这样,星系的大小仅受用于容纳种子的最大和最小数量的限制。

通往其他星系的曲速孔将放置在距起始系统一定距离的位置。 下一个星系将像这个星系的延续一样,种子数量将以同样的方式增加,并且位于星系曲速孔另一端的系统将只是“东”或“北” “从启动系统连接。

顺便说一句,与上述解决方案不同,这种增加种子的使用会导致形成网。 另外,您可以看到该方法使用四边形,而上述解决方案使用六边形,这使得无法创建网络。

当然,所有这一切都基于这样的假设:所有种子都会生成与任何其他序列不同的随机数字序列。 这使得每个系统都是独一无二的。

This is my second, improved solution. The player will start out in a randomly generated solar system. Each system is connected to between 1 and 4 other systems. Think of them as north, south, east and west systems. If a player were to move through the north jumpgate, he will be taken to a system whose seed is one more than the system before. If he goes south, the seed for that system will be one less. 2+ and 2- for east and west respectively. The distances to those systems (in parsecs or lightyears or whatever) are calculated with the systems' seed and the direction from which you are arriving. This way, the size of the galaxy is only limited by the max and min of the number used to hold the seeds.

Warp holes to go to other galaxies will be placed a certain distance from the starting system. The next galaxy will just be like a continuation of this galaxy in that the seed numbers will be incremented in the same way and that the system that is on the other end of the galactic warp hole will just be an "east" or a "north" connection from the starting system.

By the way, this use of incrementing seeds leads to a web, unlike the above solution. Also, you can see that this method uses quadrilaterals while the above solution used hexagons, which made it impossible to create a web.

Of course, all of this is based on the assumption that all of the seeds will generate a random sequence of numbers that is different from any other sequence. This makes it so that each system is unique.

幸福丶如此 2024-07-18 01:07:53

我怀疑您将面临的最大问题是拥有一个命名系统,以对玩家一致且有意义的方式命名所有这些对象 - 尽管我们确实有 系统地命名真实物体。 我忘记了 Elite 的命名约定是否在某个点后崩溃了......

I suspect the biggest problem you're going to face is having a naming system to name all these objects in a way that's consistent and meaningful to the player -- although we do have schemes for naming real objects systematically. I forget whether Elite's naming convention broke down after a certain point ...

眉黛浅 2024-07-18 01:07:53

从数学上讲,您想要随机/伪随机生成一个无向连通图。 在此图中,每个节点都是一个太阳系,每条边都是一个跳跃门。

1)创建N个节点并随机分配每个节点一个空间坐标。 这些节点最终将成为你们的太阳系。

2)使用Deluanay三角剖分算法生成边。 我建议 Deluanay 三角测量,因为它会创建一个相当漂亮的地图,没有任何门相互交叉,但您实际上可以使用您想要的任何算法。 我真的不知道你在找什么。

3)如果您使用Deluanay三角剖分,我建议您消除一定数量的边以创建“稀疏”。 这将使地图变得更加有趣,因为某些地点将成为交通枢纽,而其他地点则只是停靠站。

4) 保存该图。 这是你的宇宙。 不要放错地方或扔掉你的宇宙。 按照您想要的方式高效存储,但不要删除任何信息。

5) 为每个节点分配一个种子,并使用该种子生成每个太阳系。

6) 恭喜,您现在拥有一个具有任意数量的太阳系和跳跃门的宇宙。

Mathematically, you want to randomly / pseudo-randomly generate an Undirected, Connected Graph. In this graph, each node would be a solar system and each edge would be a jump gate.

1) Create N nodes and randomly assign each a spatial coordinate. These nodes will eventually become your solar systems.

2) Generate edges using Deluanay triangulation algorithm. I suggest Deluanay triangulation because it will create a fairly nice looking map without any gates intersecting each other, but you can actually use any algorithm you want. I don't really know what you're looking for.

3) If you used Deluanay triangulation, I suggest that you eliminate a certain number of edges to create "sparseness". This will make the map more interesting as certain locations will become transport hubs, while others are simply pit stops.

4) Save this graph. This is your universe. Do not misplace or throw out your universe. Store it as efficiently as you want, but do not delete any information.

5) Assign each node a seed, and use this seed to generate each solar system.

6) Congratulations, you now have a universe with an arbitrary number of Solar Systems and Jump Gates.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文