Say I want to trigger some event with a certain likelihood throughout gameplay. For example, say I want there to be a 5% chance of engine failure in a spaceship simulator that runs for an indeterminate length of time.

When and how do I determine if that event will occur? If I determine it will occur, how do I determine when it will occur?

The problem I see is that if you calculate the chance of a failure every tick, then there's a 5% chance of failure per tick, which means over two ticks there's more than a 5% chance - something like 8% I believe. Once the game ticks 1,000 or 1,000,000 times, it's almost certain the engine will have failed (~100% chance) when there's only supposed to be "a 5% chance."

Say we somehow knew the game would last for ten minutes - then we could get a random number 1-100 and if it's 5 or less, say the engine will fail within those ten minutes. But then at minute 5, say the player upgrades his or her engine to a 2% failure rate. We could again roll the die and if we get 2 or less, the engine will fail within the next five minutes. But again, we've calculated the chances of failure twice, which means it's more likely to fail than if we calculated those chances only once.

When we look at in-game items, they never say "5% chance of failure per frame, per minute, per game, etc." What does "x% chance" really mean and how do we get a computer to tell us if and when the event will occur?

  • I don't know what engine you're using but what I would do is on the level start I would calculate the chance once and then invoke the method for the event happening with a random delay time. – Tartle Wizard Jan 18 '17 at 17:52
  • Regardning your last paragraph, can you give us such example of game - with tooltips staying similar to the "5% chance of failure"? (not counting "on use" e.g. lockpick) – wondra Jan 19 '17 at 0:25
  • @wondra, I was thinking specifically of the engine example, but some games with weapons won't necessarily say a sword has a 5% chance of breaking per use. – codepants Jan 19 '17 at 19:50
  • I was just curious because I cannot remember a single game that does that, may that by sword or engine. – wondra Jan 19 '17 at 22:15
up vote 1 down vote accepted

With in game items, their effects tend to be either permanent, or applied by use. So it would be 5% failure each time you use the object. So a weapon would not have the effect applied until it is used to attack something. Permanent effects rarely have any % failure chances, instead, they do things like +1 to damage, or -20% dodge. Modifying a stat directly with no randomness.

The other option, applied with use, or a condition, is simple. Lets take an example of a sword. It has a 1% chance of breaking. Every time it hits something, then we roll a dice calculating 1-100, then if it is 1, then the sword breaks.

With regards to the length of time, you simply do not check until the time required has passed. So if the engine has a 5% chance of failure if it has been running for X amount of time, then simply do not roll the dice until X amount of time has passed.

Lets say we have a spaceship, and if you run the engines at 90% or more of maximum speed for 5 minutes, there is a 5% chance they will explode. For the first 5 minutes, the program doesn't roll any dice. After 5 minutes has passed, it starts rolling the dice each tick. We simply start counting when they hit 90% of maximum speed, and stop when they go below 90%. Of course, this opens up an exploit that lets them drop below 90% to reset the counter. But we can get around this with some form of cooldown, perhaps pausing the counter while the speed is below 90% during this period.

Then there are ongoing, like you have pointed out. Developers can check every frame, which would rapidly increase the chances, or after so many frames/time.

Honestly, 5% of failure is ambiguous, and varies on how the developer has developed the system. It really is a way of telling the user that there is a chance something bad can happen, and they can tell that a 2% failure engine is better than a 5%. The average user doesn't really need to know that the game only checks this once every minute, or whenever they change speed or direction. And for the special user who has spreadsheets detailing every tiny chance or difference between engines, you can bury it in documentation or let them figure it out on there own.

5% chance of failure is very high. I assume, that in your simulator longer the flight takes, more break-downs should appear. There is bias about chance. Fair toss of the coin has 50% chance of head, or 1:1 head:eagle. If you do 100 tosses, how many heads have you seen? Can be 0 or 100 or something between, rarely 50:50. N. Taleb More scientific reading This is the same problem you are facing.

Most of the game has chance given to some action, like enchantment. Really depends how you want to build you mechanics. What should player feel. It can for example effectively limit the distance the ship can reasonably travel and so on. You can put your variables in Excel and change those to get expected results.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.