Weighted Random selection with dynamic adjustment with just 8 behaviors.

HopscotchHopscotch Member, PRO Posts: 2,782

What is it good for?

Imagine you want waves of enemies, randomly spawned ...

... but you would like to start with more of the easy monsters in the beginning,
then as the level progresses, increase the frequency of tougher enemies.

Or simply define the type and frequency of enemies per level.

(Project attached)

Comments

  • SocksSocks London, UK.Member Posts: 12,822
    edited May 2017

    Amazing stuff !! Thanks for sharing !! :)

    P.S love the interface too !!!

  • ArmellineArmelline Member, PRO Posts: 5,406

    Love it! Can't wait to take some time to dig in to exactly how it works!

  • gingagaminggingagaming FREELANCE GS DEV Member Posts: 1,692

    Great work Roland!

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    Very cool and very handy! Thank you so much for sharing!

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881

    This is great! Thanks for sharing with the community!

  • HopscotchHopscotch Member, PRO Posts: 2,782

    Thanks for the comments @Socks, @Armelline, @gingagaming, @Braydon_SFX, @RThurman !

    @Armelline said:
    Can't wait to take some time to dig in to exactly how it works!

    After messing about, the simplicity surprised me:

    Make a table with enemies, adding the desired ratio each should appear. The order does not matter.

    Now pick a random value from the sum of the ratios.

    Then loop over the enemy table, subtracting each ratio from your random number until you reach 0 or less. The previous enemy is then the one to spawn.

  • SocksSocks London, UK.Member Posts: 12,822

    @Hopscotch said:
    After messing about, the simplicity surprised me:

    Things are always 'simple' once you've worked out the answer.

    @Hopscotch said:
    Now pick a random value from the sum of the ratios.

    Then loop over the enemy table, subtracting each ratio from your random number until you reach 0 or less. The previous enemy is then the one to spawn.

    Oh yeah, that was really obvious, I'm surprised you even had to work it out :p :)

  • PhilipCCPhilipCC Encounter Bay, South AustraliaMember Posts: 1,390

    @Hopscotch Snippets of brilliance like this inspire me with some great ideas that I would never attempt on my own without your tutelage. Once again, thank you. :)

  • HopscotchHopscotch Member, PRO Posts: 2,782

    @Socks :D Well, yeah, things always get lost in translation somewhere between my brain and mouth, I blame it on a sinus condition.

    My pleasure @PhilipCC :)

Sign In or Register to comment.