• Welcome to the new COTI server. We've moved the Citizens to a new server. Please let us know in the COTI Website issue forum if you find any problems.

Random Topic: Dice!

Here's something that takes game mechanics down to the bare metal:

Dice.

Let's say you have charted 'r' number of possible random results to your player's actions. You want to figure out how many of what kind of dice to roll. For our example, we'll say that there are 16 possible devices to be found in "Honest Eddie's Pawn & Bail Bond Emporium." Applying the following formulae...


c = (s ^ n) = Total number of Dice Combinations
n = (r - 1) / (s - 1) = Number of Dice
r = ((s - 1) * n) + 1 = Range of Results
s = ((r - 1) / n) + 1 = Size of Dice

r = 16 {1 ... 16}

We come up with...

n = 1, s = 16 :: 1d16 (c = 16)
n = 3, s = 6 :: 3d6-2 (c = 216)
n = 5, s = 4 :: 5d4-4 (c = 1024)
n = 15, s = 2 :: 15d2-14 (c = 32,768)

Using only one die (1D or 1d6) yields a completely flat probability for each dice combination. If more dice are used, and their throws are summed, the less linear the probable outcome will be. Thus, 15d2-14 yields a range of results from 1 to 16, but has the most non-linear curve of probable outcomes (a 'Bell' curve) of the other dice combinations.

Pythagorean dice are 4, 6, 8, 12, and 20-sided. A coin is 2-sided. 10-sided dice are common. I generally stick to these values IMTU.

If r = 10 {1 ... 10}, then possible dice combinations are 1d10, 3d4-2, and 9d2-8.

If r = 100 {1 ... 100}, then 1d100 (percentile dice), 9d12-8, 33d4-32, and 99d2-98 could be used.

Programmers, of course, could used any size of 'dice' in their programs, but the principle still stands.

The only thing I haven't figured out yet is how to determine (for example) how many times I'll roll "11" on 5d4-2 {3 ... 18} using only a mathematical formula. A little help, please?

Thanx!
 
On 2dS:
M=S+1
P(x)=S-|(M-S)|/Σ(1,2,...,S)+Σ(1,2,...,(S-1))
P(x)+=P(x) + P(x+1) + ... + P(2S)

on 3dS
P'(x)=Σ{P(x-1),P(x-2),...,P(x-S)}/S
etc.
 
You've described function P(x) very nicely. Is there an algebraic form that the rest of us can use?

Example: If 'y' equals the amount of summed dice combinations for a value of 'z', then what is the value of 'y' for 5d4-2 if 'z' equals the value of 11?

Remember... this is an open-book, take-home quiz... and show your work!

;)
 
That IS algebraic form.

what you want is equation form rather than function form. THAT I can't help with.

In general, though, I use iteration, in python.

</font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">#!/bin/python
count = 0

#Make certain that there are enough zeros to go to max of all dice
res = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

# include the values of all faces inside the brackets.
# add one line and variable per die;
# keep a progressive indent; python is indent sensitive.
for a in [1,2,3,4]:
for b in [1,2,3,4]:
for c in [1,2,3,4]:
for d in [1,2,3,4]:
for e in [1,2,3,4]:
# set s to equal the sum of the dice
s=a+b+c+d+e
# nothing below here changes
res=res +1
count = count + 1

# output the result
y = 0
z = 0
print "N", "N=", "N-", "N+"
for x in res[:]:
w = count - z
z = z + x
print y,x,z, w
y = y+1
print "of", count</pre>[/QUOTE]</font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">N N= N- N+
0 0 0 1024
1 0 0 1024
2 0 0 1024
3 0 0 1024
4 0 0 1024
5 1 1 1024
6 5 6 1023
7 15 21 1018
8 35 56 1003
9 65 121 968
10 101 222 903
11 135 357 802
12 155 512 667
13 155 667 512
14 135 802 357
15 101 903 222
16 65 968 121
17 35 1003 56
18 15 1018 21
19 5 1023 6
20 1 1024 1</pre>[/QUOTE]
 
Oh, yeah, to find the value for a shifted result, look up as tho' the sign on the dm were reversed and applied to the TN instead.

So, for 5d4-2, I find your lookup value (11), and add 2, to get 13

so on 5d4:
P(13)=135/1024
P(13-)=667/1024
P(13+)=512/1024

which is mathematically the same as:
on 5d4-2
P(11)=135/1024
P(11-)=667/1024
P(11+)=512/1024
 
You forgot a very important law of gaming probiblity.
Plot the coordinates of any given player at two intervals. Find the average slope of the player based on alchol consumption and subtract by the number of beers you have consumed. This will tell you the probibably that the dice roll will be used. The closer the player slope is to “0” the higher the probiblity if ignoreing the dice.

y2-y1/x2-x1 –q

Let q =your beers.

I think think you will find this works nicely.

Now back to the Big Math™
 
Originally posted by Heretic Keklas Rekobah:
The only thing I haven't figured out yet is how to determine (for example) how many times I'll roll "11" on 5d4-2 {3 ... 18} using only a mathematical formula. A little help, please?
General formulas for this stuff are messy and involve an implied summing procedure that's too much to do by hand. So you have to do it with a program. Yet for the domain of die rolls you're likely to see in a game, monte carlo methods are good enough and much easier to write.

So you don't really need to know the formulas.

If you still need to find them and can't program well, consider 5d4 as the polynomial (x + x^2 + x^3 + x^4)^5 and use a good math program to figure out the coefficient of x^13. That's the number of ways to roll a 13 on 5d4.
 
Originally posted by Genjuro:
</font><blockquote>quote:</font><hr />Originally posted by Heretic Keklas Rekobah:
The only thing I haven't figured out yet is how to determine (for example) how many times I'll roll "11" on 5d4-2 {3 ... 18} using only a mathematical formula. A little help, please?
General formulas for this stuff are messy and involve an implied summing procedure that's too much to do by hand. So you have to do it with a program. Yet for the domain of die rolls you're likely to see in a game, monte carlo methods are good enough and much easier to write.

So you don't really need to know the formulas.

If you still need to find them and can't program well, consider 5d4 as the polynomial (x + x^2 + x^3 + x^4)^5 and use a good math program to figure out the coefficient of x^13. That's the number of ways to roll a 13 on 5d4.
</font>[/QUOTE]What Genjuro said, and welcome to CotI Genjuro.

From the sophistication of your post HKB you probaly know that the polynomial Genjuro provided is often called the generating function. More generally, for M four sided dice the polynomial you want is:
(cx + cx^2 + cx^3 + cx^4)^M
where c=1/4.

The generating function is very useful to get the probability distributions of all sorts of sums of dice, even unfair dice. Say you wanted the probability for the sums of X n-sided + Y p-sided + Z q-sided dice, all being fair dice, you can solve the polynomial:

(ax + ax^2 + ... ax^n)^X * (bx + bx^2 + ... bx^p)^Y * (cx + cx^2 + ... cx^q)^Z

where a=1/n; b=1/p; and c=1/q, and x is just a dummy variable.

It's all just tedious algebra but if you have an even more tedious commute it can be quite entertaining.
 
Or it can be 30 seconds of run time and 10 minutes of programming to brute force the answer, as I did.
 
I typically use the brute force method in Excel: build a table showing all the combinations, then count all the results (how many 11s, how many 12s, etc.).

This does become very hard above 4-5 d6, though. Ask WJP, as I did some number crunching for his CTI (pre-UGM), and built a large enough Excel file I couldn't subsequently open it.
 
Fritz:

Python is freeware. www.python.org

Grab it, grab the script above, and edit (it's really straightforward), and voila! Far easier, since python does the iterations for you. (BTW, don't use the range(x,y) command; it is flaky... iterate the faces. This also allows odd dice like Formula Dé and d6averaging {2,3,3,4,4,5})
 
I would recommend Aramis approach, too.
Though I dont know what kind of computer Aramis uses, as it takes looong 30 seconds to do the calculation
Seems to be a pretty old one...
 
Originally posted by Ptah:
What Genjuro said, and welcome to CotI Genjuro.
Thanks, it's great to discover a thriving Traveller community.

I wouldn't multiply out the polynomials by hand. Or rather, I like just working with the exponents.

First ignore the order and write out the combinations that result in a value of 13. This isn't so hard since you're ignoring order and keeping things sorted:
44311
44221
43321
43222
33331
33322
That's it.

Now you can count up how many of each there will be and add them together. In this case there will be 5! for each roll, divided by 2! for each pair of matching dice in the roll, 3! for each triple, etc. So 44221 has two pairs, which means 5!/(2! 2!) combinations, which is 5*4*3*2/(2*2) = 5*2*3 = 30. This is the answer you get for each pattern of "two pair" so you don't have to calculate it over...

So we get:
44311 "two pair" = 30
44221 "two pair" = 30
43321 "one pair" = 5!/2! = 5*4*3 = 60
43222 "three of a kind" = 5!/3! = 5*4 = 20
33331 "four of a kind" = 5!/4! = 5
33322 "full house" = 5!/(3!*2!) = 5*2 = 10

Total: 155 ways, out of 4^5 possible rolls.

It's possible to get pretty fast at this, and since you only have to do about half the results it's not TOO bad to do by hand if you have to, or if you're sufficiently bored.

Yes, I"m a dice nerd. :rolleyes:
 
Anyone can do the brute force method. And any programmer worth his bits can have a computer do it for him.

Maybe I'm old fashioned, but I like banging out the results on my TI-35. There is even a certain elegance in using my Pickett slide-rule.

F'rinstance, I'll calculate resonance, impedance, and line length with a slipstick and a Smith chart before I'd plug the initial values into someone else's program and trust their work. With my archaic methods I can observe trends, trap errors, and track my own progress. With software, I have to trust that the programmer understands the theory, wrote bug-less source code, and used a compiler that wasn't having a bad hair day. It's like that old cartoon that shows two formulae on a blackboard, separated by the words "A Miracle Occurs".

F(x) = [The Hidden Miracle Function acting on the variable x]

But that's just me. Your results may vary.
 
TE:

Problem isn't a slow computer (well, it's not blindingly fast, either... 1.25Ghz PPC-G4); it's that Python's output routines are console (stdio) based, and therefore slow, and I'm running it through the IDE, rather than at the command prompt. Also, Python is interpreted. But it's free, easy, and powerful

The calculations take under a second. The output takes time as it scrolls by.
 
Back
Top