Greš na zmenek, pojdi na romantična potovanja, se sestaneta, ko delaš za skodelico kave ..…
“Accidents are not accidental, it’s all a big deception.”or how random elements work in games.
Good day StopGame! Today I will tell you how elements of randomness (random events) work and how developers actually create certain situations where these elements are required. Let me clarify right away for better understanding: randomness is random. I will try to tell you as concisely and understandably as possible. Well, let’s go!
ABOUT TYPES OF RANDOM ELEMENTS
Few people know, but the computer cannot create a completely random number, what algorithms would not be used. The number generated will always depend on something and will not be completely random. A computer is a machine and it obeys mathematical algorithms and formulas, and randomness, in principle, is the direct opposite of any mathematical rules. Developers always use tricks to create the illusion of randomness as plausibly as possible, but it still cannot be called complete randomness.
In fact, there are several situations where the use of random elements is required:
1.Procedural generation (creating terrain and worlds).
2.“Honest” generation of items (Dropping items from enemies, chests, etc.).
3.“Unfair” generation of items (Cases in games purchased for real money).
4.Situations where the entire game is based on elements of randomness. (Playing cards, six-sided dice games)
5.Various situations that should occur at random times (For example, weather changing from sunny to rainy).
Let’s look at each selected element in more detail. (if you forgot to add something to the list, please leave a comment. If there is a really interesting and constructive comment, I will add to the blog).
Procedural generation
Of course, this word means not only the creation of a landscape and environment, this includes the location of objects in a location, characters and much more, but the most popular method of use is still the generation of random worlds. A striking example is the creation of a world in Minecraft, where procedural generation works, it creates absolutely the entire environment around the player (all blocks, chests, enemies, objects, characters, etc.) and let’s figure out how it is created. In fact, the algorithm has changed more than once, but today it works like this:
Did you know that Slottiocasino.co.uk the world in Minecraft is not endless?? It is 30 by 30 million blocks. When generating (not only in Minecraft, in many games as well) the so-called "seed" – initial value.
To create a unique world, create this initial value from random numbers and symbols. Almost no method works without it PRNG (Pseudo Random Number Generator). But since the computer cannot create anything random, the game takes the date and time on the computer as random numbers. If you try to create two worlds in a game with the same date and time (for example 20.10.2020, 18:34), then you will get two absolutely identical worlds. But the creation of the “seed” does not end there; then this initial value is converted into a 32-bit number using several formulas. Afterwards, a number is obtained that is applied to another method – Perlin noise.
Perlin noise actually has nothing to do with sound, it is essentially a picture (example in the image below) with many shades of gray, white and black colors.In very simple terms, the darker the pixel in the Perlin noise image, the higher (or lower) the landscape is created.
Let’s take the following example (very simplified, in reality everything is more complicated, there are a lot of “filters” for the subsequent “polishing” of the world). In the noise picture there are pixels of only three colors (no shades): white, gray and black, then the Minecraft world can be generated with a landscape of a maximum height of 3 blocks. The air block will be white (essentially the absence of a block), the terrain thickness will be 1 block, and the terrain thickness will be 2 blocks black. But such Perlin noise is usually called two-dimensional.
The game uses mainly three-dimensional noise (3D) (but two-dimensional noise also works for “polishing”), since using only two-dimensional (2D) it would be impossible to create, for example, caves and various buildings. Below you can see the 2D noise. In the first picture you see the noise itself on the left, and on the right the result of creation (I found an unsuccessful example, on the right some kind of 2D game is being created). In the second picture you can immediately see the result of Perlin noise already in the game engine. The third and fourth pictures show everything more clearly.
This is roughly how all procedurally generated worlds are created; Perlin noise together with pseudo-random number algorithms remain perhaps the most popular and simplest. I tried to describe it as clearly as possible, but I admit that it is still too difficult to understand. Write in the comments if it’s not clear, I’ll improve the blog. Well, let’s move on to the next element of randomness. You can learn more about procedural generation in more detail and much more interestingly from the video below:
“Honest” and “dishonest” item generation.
What do I even mean by “honest”?? I mean honest the generation of items that does not depend on server data and the probability of such items falling out is generated by the engine, and not by developers or publishers.
Let’s give a conditional example: you have a game in which there are 4 types of rarity of an item: Common, rare, epic and legendary. For example, you approach a chest from which these things will fall out to you, and the system where the randomness algorithm is not changed by the developers after release at will will be fair. That is, if you get a legendary item, for example, then you are “lucky”, since the required number came up in the algorithm, but if not, then the probability of getting this item will not change based on the previous item received.
Simplified, this system works like this: let the probability of dropping items be as follows: common (70%), rare (20%), epic (9%), legendary (1%). All this gives a total of 100% probability, and then the algorithm will look like this: if randomly entered number is in the range from 0 to 70, a normal item will drop out, if from 71 to 90, a rare item will drop out, if from 91 to 99, an epic item will drop out, and if the entered number is 100, a legendary item will drop out. The element of randomness here is this very entered number. Where can I get this random number?? There are actually a lot of ways: from the previously mentioned seeda (just take its last two numbers), to listening to atmospheric noise and microphone noise for its subsequent conversion into digital form (this is how the popular site works: Random.org).
However, StopGame is a gaming portal, so let’s find out how such numbers are generated in the two most popular game engines: Unity and Unreal Engine.
-In these engines, one of the methods is “XorShift”, which takes the date and time on a PC as a seed, then converts the resulting number into the binary number system, then sums this number several times with a shift to the right and left, after which the resulting number is cut off to the length of the original and a pseudo-random number is obtained. This method is described in more detail and clearly in the video below.
Let’s now talk about "unfair" item generation.
This method is most widely used in online games such as “Warface”, “Overwatch” and “CS:GO”. They also use a principle based on probabilities, as in the “honest” method, only in contrast to it, the dishonest method changes its probability depending on previously obtained data. Now in simpler terms: if you get a “legendary” item with a chance of 1%, then the next “legendary” item will already have a drop chance of, for example, 0.5% or less, and “ordinary” things with a chance of 70%, on the contrary, will raise their chance of falling out, for example, to 80%, so after several attempts to open conditional “cases in CS:GO”, the chance will increase until it again reaches its maximum of 1%, and the chance of a “normal” item falling out will not drop to 70%.
Naturally, a dishonest method is usually needed in order to make a profit from players, because excitement and the illusory hope that “a legendary will appear soon, I feel it” makes players spend money on this kind of cases, roulettes, bets and casinos. The entire process is controlled by the developers and they can change the probability parameters at any time, since all algorithms are located on a remote server. Let’s now talk about the next element of randomness.
Situations where the entire game is based on elements of randomness:
I’m talking about those games where your victory directly depends on the initially (or in the process) obtained random combination of elements. The most striking example of this in real life is playing cards. A man shuffles the cards with his hands and then distributes them to all players. But how can the computer shuffle the cards?? In fact, you can use a very strange, but working method: mouse arrow tracking.(I don’t know if this method is used specifically in card games, but it is present in many projects). The computer tracks the X and Y coordinates where the mouse is currently located and takes only the last digit from each coordinate. Let’s say the mouse arrow is at coordinates X=54 and Y=27. The algorithm will take only 4 (from the number 54) and 7 (from the number 27) to create a random number, then there can be many functions, the numbers can be added, subtracted, multiplied, divided and obtained any other new pseudo-random number. Next, the cards are numbered, say from 0 to 36, add up the previously received 4 and 7, we get 11, which means the player will get card number 11 from the deck and so on until the players receive the required number of cards. Naturally, all mouse movements are tracked, say, per minute, since if you look at the current coordinate of the mouse each time, the pseudo-random number will always be the same if the mouse does not move.
I really hope that you understood what I wanted to say, I tried to explain clearly, but my manner of speech and narration of course “leaves much to be desired”.
Let’s move on to the last element of randomness that I was able to formulate.
Various situations that should arise at random times.
An example is rain and thunderstorms from the same “Minecraft”. In fact, there is no chance there, the frequency of rains depends on the same “ill-fated” seed that was created during the generation of the world. For certain seeds, the rainy period changes, thanks to calculations using certain formulas (which Mojang does not show). Roughly speaking, in one world, with one seed, rains occur once every 5 game days, in another world, with another seed, the frequency will be, for example, once every 7 game days. There are no elements of randomness here at all, everything happens naturally and according to formulas.
Truly random situations in games are used very rarely, but they are still present. Let’s take a look at their work.
Take the example of the traveling merchants in Dying Light. I can’t assure you for sure that everything will work exactly as I say, since ordinary users do not have access to the source code of the “engine”, but everything hints at exactly this method.Merchants spawn at random times (determined via GPS) with random goods in random locations. But here, unfortunately, there is no truly random element. Merchants appear in specially prepared places that the developers have chosen for them, and sell goods, which are also not randomly generated (the goods are created from specially prepared sets of items, which the developers also managed to make earlier). Also, prices for goods can change up or down with just one formula (decreasing percentages to the original price of the goods), thereby attracting the player with a “temporary discount and limited supply,” but all this is just an illusion of deception.
I would like to believe that you do not think about wasting your time reading this blog, I tried to make it clear and interesting, but it turned out bad “as always”. I don’t say goodbye, I’ll see you again in the open spaces of StopGame.ru
