Coding Luck into a Game
Hello everybody, Geek Generation here.
In alot of games, there’s usually some randomness, rng component, in it. For some games, rng comes in the form of gacha boxes. Click on the link to the Gashapon wiki to understand what i’m talking about. Basically it’s a box that gives you random loot after opening it. There’s usually some randomness in loot drop when you kill monsters, and we can perceive that as the monster, on death, dropping a gacha loot bag that opens automatically.
Randomness is not limited to opening cash shop (usually) gacha boxes. In Path of Exile, randomness exists in the use of its currency. When you use an Orb of Alteration on your magic item, the affixes you get are randomly taken from a fixed pool of affixes.
There are usually alot more randomness all over a game. For the purposes of this post, these few mentions should be sufficient to let you know about the existence of randomness in a game and where it can exist. That is, if you don’t already know/understand it.
For alot of players, there seem to be a belief in a property called luck. The belief in luck is not trivial and it resulted in a friend saying to me something like, “I’ll keep this gacha box in the warehouse first and open it when i have good luck.”.
Say if i were a programmer, i could have a line that goes like:
Loot_Index = rand() % 100;
Basically that goes like, give loot index a random number from 0 to 100. So that line of code would probably exist and be compiled into some form of runnable program in either the game client or the game server. If luck is capable of affecting probability, how does it do it? Does luck affect computers?
Say the programmer were extraordinary and is beyond human comprehension and codes luck into the game code, how would it look like then?
Loot_Index = (rand() % 100) * Get_Player_Luck();
Maybe that would work, but it doesn’t. Because what we have is a loot index that lets us point to a location in a loot table. Consider the following loot table.
0 – Garbage
1 – Garbage
2 – Desirable loot
3 – Garbage
4 – Garbage
5 – Garbage
6 – and so on
As you can see, desirable loot could be randomly positioned in a loot table. It should be obvious that the code for producing luck infused loot is alot more than complex that one line of code. It involves knowing which loot in the loot table is desirable to the player, knowing the player’s current luck status (whether good or bad), and then depending on the player’s current luck status, employ a mathematical algorithm to normalize the loot index toward/”away from” the loot table index(es) that has the loot desirable to the player. And that’s not even mentioning how a Get_Player_Luck() can possibly be coded.
Good luck with writing such a code, no pun intended.
I have more to say regarding luck, but this is getting too long, i’ll break it up into more than one post. Geek Generation out.