Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 995363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:42:39+00:00 2026-05-16T06:42:39+00:00

In my game, I would like to spawn N items, not necessarily at the

  • 0

In my game, I would like to spawn N items, not necessarily at the same time. Some of the items are dependent on what was spawned before (Markov chain-esque), so the probability of spawning two rocket launchers in a row is low, but there’s a reasonable probability of spawning a rocket launcher followed by rockets. What would be the most efficient way of doing this? The method will be called very often, so I’m trying to keep calculations to a minimum.

An idea I came up with could be to create an N x N array which acts as a lookup table of the probabilities (Item previously spawned VS Item to spawn). However, in this process, I would need some way of generating a random number with the probability acting as a bias. I am not sure what the best way of doing that is. Things also get slightly tricker when an inventory comes into play, as rockets cannot be generated if Y amount have already spawned. I could create a 3D array and store the inventory number in there, but I’m not sure how efficient it would be to keep updating an array lookup table based on inventory.

That’s just an idea I came up with, but there’s probably another, better, way of doing this. Are there any data structures that would be more efficient than a 3D array, or algorithms I should read up on?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:42:39+00:00Added an answer on May 16, 2026 at 6:42 am

    The most efficient way, if you don’t need much state stored, is to do just what you hinted: create a Markov chain. Associated with each state is an array of probabilities of exit to the next state. This gives you complete control over the process and is pretty compact. (Note that you use it by generating a random number from 0 to 1 and doing a binary search on the cumulative probabililties.)

    An alternative, fuzzier approach is to maintain a set of probabilities and a set of biases. If you have a bias term like

    launcher_bias = 0.8*launcher_bias + 0.2*(1.0 - (last_item == launcher))
    rocket_bias = 0.8*rocket_bias + 0.2*(last_item == launcher)
    

    and you weight your probabilities with these values (and then renormalize the whole set to 1, or equivalently if the total probability of all items ends up at 0.7 or somesuch, you pick values from 0 to 0.7) you will find that as you get excess launchers the probability of getting more will drop. But, at the same time, you’ll increase the chance of getting rockets. Basically, you’ll have some exponentially decaying weighting factor that prejudices you against launchers if you’ve had one recently.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a little game where user would simply move some
I'm not a graphics or game designer but would like to build more interactivity
I would like to program a computer game which should be played by several
I would like to know How to create a fps-game with SDL lib? Are
I would like to use Swing to program a simple learning game. I am
I built a slideshow/decision-making game in Flash but would like to try to redo
I am making a small game in flash, I would like to track scores
I'm making a game and would like to know how I get a keypress
I'm trying to be fair play in my network game and I would like
i have written a standalone connect 4 game. next i would like to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.