Author Topic: Weighing the dice  (Read 4833 times)

AgingMinotaur

  • Rogueliker
  • ***
  • Posts: 801
  • Karma: +2/-0
  • Original Discriminating Buffalo Man
    • View Profile
    • Land of Strangers
Weighing the dice
« on: July 03, 2014, 11:23:07 AM »
In my game, most dice rolls are compared to a probability expressed as a fraction. Eg. you have a 1/3 probability of missing your shot or a 1/6 probability of scoring a critical hit. Right now, I just do something like this:
Code: [Select]
def roll_die(numerator,denominator):
   die_roll=random.randint(1,denominator)
   if die_roll<=numerator: return True
   else: return False

This "just works", and on a simple enough level for even me to understand, but I've been thinking about drawing dice rolls from a set pool of results. This would mean results are more stable over time, but should still allow for streaks of bad/good luck and so. Accompanying functions might look something like:
Code: [Select]
result_pool=[]
for i in xrange(1,601): result_pool.append(i) # insert numbers 1 though 600 into list
def roll_die(numerator,denominator):
   die_roll=result_pool.pop(random.randint(0,len(result_pool)-1) # pops a random number, removing it from the list
   result = Fraction(die_roll,600)
   prob = Fraction(numerator,denominator)
   if result<= prob: return True
   else: return False
… and whenever result_pool gets empty, refill with numbers 1-600. This kind of solution is commonly used, though I don't exactly remember it's name at the moment. (I'm using something similar for monster placement in the upcoming release, and it yields a nice and balanced result: RNG can still screw you over during map generation, but you won't get either levels devoid of life or levels that are just cramped with enemies.)

A few questions:

* How large would you deem it reasonable to make the result_pool list? A smaller list yields more predictable results, obviously. The base probability for most actions is 5/6, and I can't imagine any probability going below 1/60 or above 59/60, so I can probably go as low as that – len(result_pool)==60, that is. But the player shouldn't be "counting bullets" either, in the sense of being able to know that "currently, my nominal P=1/6 in practice translates into P=1/2."

* Would it be a good idea to keep separate result_pool lists for the player and for other critters? If the idea is to "even out" the results a bit, the player can still get screwed if pulling all the bad results while mobs pull all the good results. I guess keeping one list for the player plus allies, and one list for opponents, seems fair.

Any thoughts? Maybe I'm just wasting time thinking about this. I definitely think it makes sense to nudge stuff like encounter/treasure tables in this way, but not so sure it really has much to say for tactical dice rolls. And too much predictability is not a good thing, either.

As always,
Minotauros
This matir, as laborintus, Dedalus hous, hath many halkes and hurnes ... wyndynges and wrynkelynges.

Omnivore

  • Rogueliker
  • ***
  • Posts: 154
  • Karma: +0/-0
    • View Profile
Re: Weighing the dice
« Reply #1 on: July 03, 2014, 11:47:08 AM »
I forget the exact formula but Path of Exiles uses a variant of the technique you describe for avoiding long bad runs of random evasion rolls.  I think it is a worthwhile tool in some situations.

Aukustus

  • Rogueliker
  • ***
  • Posts: 440
  • Karma: +0/-0
    • View Profile
    • The Temple of Torment
Re: Weighing the dice
« Reply #2 on: July 03, 2014, 12:04:58 PM »
What I don't like about shuffle bags is that it forces the same results, but in different order.

For example with a d20 based shuffle bag that has numbers 1-20 it's not possible to roll the same number multiple times until all 20 different rolls have been rolled as opposed to playing with a real d20 die that theoretically allows even hundred times the same number in a row.

AgingMinotaur

  • Rogueliker
  • ***
  • Posts: 801
  • Karma: +2/-0
  • Original Discriminating Buffalo Man
    • View Profile
    • Land of Strangers
Re: Weighing the dice
« Reply #3 on: July 03, 2014, 12:56:22 PM »
What I don't like about shuffle bags is that it forces the same results, but in different order.

This is why I'm considering how big to make my shuffle bag. Most rolls will have a probability P=1/6 of success. Which means that if the total size of the bag is set to 600, you can get a hundred successes in a row. Make the bag too big, though, and you might as well be using random numbers directly.

As always,
Minotauros
This matir, as laborintus, Dedalus hous, hath many halkes and hurnes ... wyndynges and wrynkelynges.

Aukustus

  • Rogueliker
  • ***
  • Posts: 440
  • Karma: +0/-0
    • View Profile
    • The Temple of Torment
Re: Weighing the dice
« Reply #4 on: July 03, 2014, 02:23:37 PM »
What I don't like about shuffle bags is that it forces the same results, but in different order.

This is why I'm considering how big to make my shuffle bag. Most rolls will have a probability P=1/6 of success. Which means that if the total size of the bag is set to 600, you can get a hundred successes in a row. Make the bag too big, though, and you might as well be using random numbers directly.

As always,
Minotauros
600 sounds quite high though.

I have no idea about performance and memory usages but I'd put own shuffle bag for every creature including player for combat calculations. That way everybody would have the 1/6  chance that's not being used by others by picking out numbers. It's the most fair thing.

Bear

  • Rogueliker
  • ***
  • Posts: 308
  • Karma: +0/-0
    • View Profile
Re: Weighing the dice
« Reply #5 on: July 03, 2014, 04:48:41 PM »
Aukustus has a point in that if you want this to mediate luck in some way, you have to have a consistent rule that a higher number is always better for the player regardless of what purpose it's drawn for, or whether drawn by the player or by a monster. 

IOW, if the player draws a 1 and it's a critical miss, then a monster draws a 20 and it's a critical hit,  the player has just had two serious bad-luck incidents back-to-back, and the average roll available in a bag of d20 rolls is unchanged.  If you plow through the rest of the bag in like fashion, there really is no way the bag is mediating player luck at all - instead it's just a question of whether the extreme rolls are getting used for or against the player. 

That said? I do not believe it worthwhile to mediate the die rolls.  And if I did, I'd be doing it differently.

If mediating such things really became an issue, I'd be tracking player luck with a point score that decrements when something especially lucky happens and increments when something especially unlucky happens. Then I'd treat the absolute magnitude of the luck score as a percentage chance of making a second roll whenever something that would otherwise change it came up, and taking whichever roll resulted in the luck score remaining closer to zero. 


AgingMinotaur

  • Rogueliker
  • ***
  • Posts: 801
  • Karma: +2/-0
  • Original Discriminating Buffalo Man
    • View Profile
    • Land of Strangers
Re: Weighing the dice
« Reply #6 on: July 03, 2014, 05:17:13 PM »
That makes complete sense. I'll probably leave it, and maybe post a related query about loot distribution later. That's a case where it may make more sense, ie to make sure at least some healing remedies show up in every dungeon.

As always,
Minotauros
This matir, as laborintus, Dedalus hous, hath many halkes and hurnes ... wyndynges and wrynkelynges.

Kevin Granade

  • Rogueliker
  • ***
  • Posts: 83
  • Karma: +0/-0
    • View Profile
Re: Weighing the dice
« Reply #7 on: July 04, 2014, 02:39:05 AM »
I don't think fudging rolls in general is doing the player any favors, it only makes the system less legible, not more.
However, this does bring up an interesting point, what if you modeled probability in the game not how it actually works, but how people THINK it works?

I don't have any conclusions, I'm still trying to wrap my head around it, but it's an interesting question.

guest509

  • Guest
Re: Weighing the dice
« Reply #8 on: July 05, 2014, 12:41:20 AM »
Hello my cow headed friend.

I think what you are doing here is using card mechanics instead of dice mechanics, right? You pull or a set of values (cards) and then reshuffle the deck when all cards are pulled. Which makes it so that you don't have stupid runs of bad numbers?

This might work. Hard to imagine I think without testing. But card mechanics are certainly a tried and true way of doing things, but generally it works better when the player knows they've had a string of bad cards so they can be pretty sure the deck is now 'hot' or 'primed' so can predict that good cards are coming.

Just my commentary. As always if it's working then fine, if strings of bad luck are screwing you, then yea this can even things out.

Omnivore

  • Rogueliker
  • ***
  • Posts: 154
  • Karma: +0/-0
    • View Profile
Re: Weighing the dice
« Reply #9 on: July 05, 2014, 12:57:26 AM »
I had to go look up the actual mechanic used in Path of Exile Evasion after mentioning it in my previous reply, here it is:

1) If first time entity is attacked, or at least six turns since last attack, randomize entropy value from 0 to 99.
2) Calculate chance to hit (0 to 99 range depending on various factors) and add this to the entropy value.  If entropy >= 100, the check is a hit, subtract 100 from entropy.  Otherwise it is a miss, leave entropy unchanged.

The goal with this mechanic is to ensure there are no long strings of hits or misses purely by chance.


melville

  • Newcomer
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Weighing the dice
« Reply #10 on: July 13, 2014, 04:02:17 PM »
I have investigated some alternative approaches to RNG. Some discussion here is misleading, other is spot on. First let's start with approach similar to deck of cards.

You probably want a small stack with fixed content, otherwise it defeats purpose and you are better using RNG. Numbers are poped from stack, when empty replenished with numbers and then shuffled (you can find algorithms for shuffling arrays). You need only entropy for shuffling, poping numbers can be done linear. Here is example of stack with 20 element with numbers in range 1-6 (I just made it up, so nothing special):

1, 2-2-2, 3-3-3-3-3-3, 4-4-4-4-4-4, 5-5-5, 6

Distribution of numbers isn't even, so you already get different odds: 5% chance for one, 15% for two, 30% for three and so on. Let's say that one is a miss and six is a critical hit - you can actually get two of those in a row (same number at the end of one stack and at the beginning of another). This should be a rare event, also periods without misses after and before event will be longer. You will also never get more than two misses in a row.

Why small stack? If you increase size of stack, you will probably want to increase probability of poping specific number. Not only streaks will be more common then, but also those streaks will be longer. Deck/stack approach gives you control over streaks and guaranteed occurrences.

About predictability from player perspective - if you don't know where stack starts/ends it is hard to abuse. One way to mitigate that is to change size of stack a little bit, every time it is created e.g. you discard one to five elements from deck with 50 elements.


Omnivore and Bear mentioned progressive system. Similar solution is used for drops in World of Warcraft: http://www.shacknews.com/article/57886/blizzard-details-secret-world-of . I won't describe it, since article is pretty clear.


You can find some nice discussion here: http://stackoverflow.com/questions/910215/need-for-predictable-random-generator . Just to quote:

Quote
Given the behavior you're asking for, I think you're randomizing the wrong variable.

Rather than randomizing whether this hit will be critical, try randomizing the number of turns until the next critical hit occurs. For example, just pick a number between 2 & 9 every time the player gets a critical, and then give them their next critical after that many rounds have passed. You can also use dice methods to get closer to a normal distribution -- for example, you will get your next critical in 2D4 turns.

I believe this technique gets used in RPGs that have random encounters in the overworld as well -- you randomize a step counter, and after that many steps, you get hit again. It feels a lot more fair because you almost never get hit by two encounters in a row -- if that happens even once, the players get irritable.