This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Random item dropping

Random item dropping
by on (#50035)
In my game I'd like to have enemies randomly drop health or various power up as they are defeated, kinda like in Mega Man games.

The problem is that if I make it actually random (using a RNG), it will end up "too random", and there would be always some chances to get a lot of rare items consecutively. Additionally as long as the RNG isn't perfect, the number probability is likely to be a bit off.

So I decided not to make it random :wink: (kinda like the "random" encounters of Final Fantasy games).

My idea was to have a table with a lot of entries, $00 means no item is dropped, other numbers tells the number of an item to be dropped. Only the increment in this table is random, which varies between 1-4 (so it only relies on 2 bits of the RNG).

This idea woked very fine, but there is a major problem : The table takes a large amount of ROM space, and if I'd like to have stronger monsters more likely to dropp items then I have to have multiple tables, wasting a ridiculously high amount of space.

So anyone here have an idea to make item dropping not random, but in a solution that doesn't waste too much ROM ?

by on (#50037)
What kind of monsters, and what are they dropping?

by on (#50038)
How about associating a probability of dropping each item n is 256 chance, for example lets say you have a table with:

80/255 - health
15/255 - weapon
5/255 - extra life
otherwise nothing

Assuming you want to limit the drops to one item dropped at most:
you generate a random number from 0-255, and then test against the probability, and if not less then, add the next probability.

if its less than 80, you get health
80-94 you get weapon
95-99 you get extra life
otherwise, nothing.

by on (#50039)
What Bregalad wants is to avoid getting extra life-extra life-extra life or weapon-weapon-weapon by "manipulating luck" as seen in the Mega Man TAS videos.

by on (#50042)
Gimmick! uses a very simple method which entirely avoids the RNG. It works surprisingly well..... as long as the player doesn't know about it. ;)

by on (#50043)
tepples wrote:
What Bregalad wants is to avoid getting extra life-extra life-extra life or weapon-weapon-weapon by "manipulating luck" as seen in the Mega Man TAS videos.


Well that can easily be avoided by using a separate seed for the RNG used for item drops. So you can't interfere with item drops by triggering the RNG with other actions.

by on (#50045)
If you really want to ensure an even distribution of luck and nonluck, generate a permutation in advance.

For instance, you could have 16 slots, and every 4th enemy destroyed, take the top one off the queue. For example, a queue could contain 4 energy boosts, and 4 weapon boosts. You add everything to the list, then shuffle the list's order. Every 64 enemies killed will drop the same amount of stuff total. You could also have every other queue contain a 1UP.

by on (#50067)
Yeah the problem of doing it random is that for example I could do :
Quote:
jsr RandomNumber
and #$3f
bne +
jsr DropExtraLife
+....

So that there is a 1/64 probabilty to get an extra life. However in practice, the RNG isn't "linear", some numbers comes out more often than others. So you could end up having very often extra lifes that way, or never seen it even tough you defeat tousands of enemies.

What gimmick does is interesting. Maybe the problem is that isn't not enough random... Ideally it would be a combination of something pre-determined and something random.

Quote:
For instance, you could have 16 slots, and every 4th enemy destroyed, take the top one off the queue. For example, a queue could contain 4 energy boosts, and 4 weapon boosts. You add everything to the list, then shuffle the list's order. Every 64 enemies killed will drop the same amount of stuff total. You could also have every other queue contain a 1UP.

Sound interesting, but I didn't really understand that. It would mean each 4 enemy would drop something no matter what happens ? This sounds not random enough to me.

by on (#50069)
You also have blanks in the queue. The "every 4th enemy" is just to make the queue smaller with the low amount of RAM available, you could just make the queue bigger and eliminate that.

Here's an example randomly-generated 16-size queue: (with 4 lifes, and 4 weapons)
_
weapon
_
_
_
life
weapon
weapon
weapon
_
_
life
life
_
_
life

by on (#50070)
So basically you would put some items in a queue, apply some algorithm that randomize their position by swapping items of the queues at random position a lot of times (kinda like how you randomize a card deck in real life) and then pull out items of the queue ? Sounds quite a good approach. Kinda like my table solution above exept that the table is variable. So for later stages with stronger enemies I could add more items than in early stages.

I don't mind about using RAM I have a complete game engine and I still have more than 512 free bytes of RAM.

by on (#50073)
You might be able to take a cue from popular block stacking games: Bag randomizer | History based randomizer

Tetris DS randomizes the pieces with a bag randomizer: generate 7 at a time, then reshuffle once you hit the end of the queue. LJ65 won't ever generate one of the last 3 pieces as the next pieces because it moves the generated piece to the end of the queue and picks only one of the frontmost four.