开发者

How to generate monsters/weapons of a specific level?

Background

Assume that we have a game where monsters and weapons are generated "randomly".

A weapon could be defined like this:

  • type: axe (1.2) / sword (1.4) / spear (1) / club (0.7)
  • range: 1 - 3
  • magic: ice (10) / fire (10) / none (1)
  • state: sharp (2) / normal (1) / dull (0.5)

Some of these values could have dependencies (e.g. type and range).

Using a random generator we could get for example a dull Axe of Fire (range 2). Then we could have a formula that calculates the level of this weapon. Example formula:

level = floor(type * range * magic * state)

The dull Axe of Fire (range 2) would then have level floor(1.2 * 2 * 10 * 0.5) = 12.

Simple, but nice!

We could also have a world where the player goes deeper and deeper down into the dangerous caves, starting at cave level 1.

The question

Let's say the player is at cave level 12. (S)he has entered a room where we want to place a weapon in a chest.

What would be a good algorithm to generate a level 12 weapon? (or any other level of course)

I.e. we have the level and want to use a level calculation (our simple one, or another more sophisticated) backwards to generate good values for the different elements of the weapon.

Minor or major changes to the definition of a weapon can be made to facilitate a better solution.

EDIT:

It seems like High Performance Mark's solution is the best where there are a reasonably limited set of combinations. If not, or if we have continuous values and an "unlimited" set of combinations, one of the other answers might be better suited. I say "might" since maybe a lookup table could be used even in a continuous version for a subset of the values to pick a good starting point and then on开发者_如何学Ce could add a small random delta to fill in.

Example: range is continuous between 10 and 200. The lookup table contains values (10, 20, 30, ..., 190, 200). The algorithm picks 110 for range and then adds random(-5.0, 5.0) to it for a final value of, say, 108.72. Then the final level of the weapon would be close enough to the desired value to do. How does that sound?


If you have, say, 5 choices each of type, range, magic and state then you have 5^4 choices of weapon. This is quite a small number and you could easily store them all in a lookup table, indexed on the level of weapons. When you want a random level 12 weapon, you choose uniformly from the available level 12 weapons.


Based on the element you pick in the first list, what are the maximum and minimum level values you can achieve? For instance, for a club, you can achieve any level between floor(0.7 * 1 * 1 * 0.5) = 0 and floor(0.7 * 3 * 10 * 2) = 43. So, if you were looking for level 44 weapon, you should never pick a club. This helps you restrict the set of acceptable choices in the first list.

These min-max values can be computed on the fly for a simple monotonous function like this one, but it can also be pre-computed in advance if the level function is too complex.

Repeat the process for the other lists, ending with a list that allows continuous values, such as damage (being continuous lets you pick a fudge value that selects the appropriate level).

For instance, looking for a level-12 weapon, one would pick randomly an axe (min:0, max:72), pick randomly "of fire" (min: 6, max: 72), eliminate "sharp" (min:24, max:72), pick randomly "dull" (min:6, max:18), and then use a fudge value of 2 = 12/6 for the range.


If the formula for calculating the level of the weapon is simple as in this case, you may think of choosing the level randomly, and then calculate the parameters of the weapon by repeatingly divide the level by random factors.

For instance, you have the level 12. Then you randomly generate a weapon type. You get spear (1.0) and do 12/1.0 = 12. Then you randomly choose the magic and you get fire (10). Then you have 12 /10 = 1.2. You go on until you have only one parameter to set and eventually you choose that value. For a better balanced system you may decide to reorder the parameter to guess and/or the probability of the random generators depending on the current values of your guess.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜