Showing posts with label dice. Show all posts
Showing posts with label dice. Show all posts

Tuesday, March 24, 2020

7d6, split between two attributes

On 20 Feb 2020, PlanetNiles (Ey/Em) NB on the workshop channel of the OSR Discord asked1:

7d6, split between two attributes

What values are even possible?

One way to think about this is not in terms of the values themselves, but in terms of the difference between the two paired attributes. The maximum difference is when all dice are allocated to one attribute, leaving the other empty. This is then equivalent to the sum of the dice.

The minimum difference between the two is a form of the well-studied partition problem: given a set of numbers, can it be split into two sub-sets with equal sums? A heuristic method that can usually2 find the smallest difference between our two subsets (and therefore if they can be equal or not) is called the Karmarkar-Karp method, which works as follows:

  1. Take the two largest numbers in the set. Assume that these will go in opposite partitions.
  2. Because they will go in opposite partitions, we subtract them from each other.
  3. Instead of now deciding which partitions they will go in, we return the difference between them to the set. This is effectively deferring that decision until later.
  4. Repeat steps 1-3 until there are only two numbers left. The difference of these last two numbers is the smallest difference we can make with this set.
Note that we didn't actually find what the partitions are, only what the difference between them is here. I hope this is clear enough, but I'm also sure that clearer explanations can be found with minimal searching.

With some wrangling, we can produce this lovely chart, where a heavier hexagon is a more likely pairing.


Hexagons are elegant, as odd/even combinations that cannot occur are skipped naturally.

From this, it looks like the system gives a lot of flexibility in assigning scores to your attributes.

What Values are Likely?

I have a concern about this mechanic though: if you give someone a range of numbers, and tell them to pick one, they will tend to pick in the middle3. If a player is dead-set on being boring, how boring can they be?

It might not be exactly true, but we can show the distribution of all the high stats and all the low stats together, and then compare them to the distribution of 7d6 literally divided in half (which is approximately normal).

This doesn't look great, but PlanetNiles has actually already got us covered here:

Of course. I'd further consider including subsystems where the difference between attributes had some sort of effect. So favouring one over the other would prove beneficial in some way, or at least open up different options.
The strength of this mechanic then will rely on the strength of the system. Given the range of the first figure though, I have confidence that an interesting system could be built here.

What about other mechanics?

Suppose we were looking for a similar mechanic, except that it would force a difference between the attributes where possible. We might expect intuitively, that fewer dice and larger dice are harder to partition effectively. This table gives the probability of a forced difference (although does not consider the size of that difference).

From this table, I thought I would look at 3d20, because it forces a difference the most often. The figures below have the same interpretations as the similar ones above, but for 3d20 instead of 7d6.

Python

This was my first project using Python, and I think it's an all right language. It'll probably displace Octave in my repertoire, but I'm sure I'll be right back at Perl if I start doing string stuff again. The code's a bit janky, but you can take a look here.


1 “Asked” a little more directly this time, if only because I asked first.back

2 According to Wikipedia, this method is “bad for instances where the numbers are exponential in the size of the set,” so like, probably fine?back

3 I only know this anecdotally: if you tell a plant operator to keep some process temperature between a high limit and a low limit, without fail they will control it to the middle of the two. It makes sense to a person, but the optimal temperature is provably at one of the two extremes. Possibly, this is an extension of the anchoring effect.back

Monday, February 17, 2020

5d6 but only count straights and matching

On 7 Feb 2020, diregrizzlybear on the GLOG channel of the OSR Discord asked1:

5d6 but only count straights and matching.

One solution might be to list all the rolls and score each one. This is probably feasible with a script. Instead, I enumerated the “hands”, and then found the probabilities of each of those.

Hands with No Degrees of Freedom

Run of Five

There are only two runs of five: ⚀⚁⚂⚃⚄ and ⚁⚂⚃⚄⚅. There is only one way to “make” each of these hands (“Count”), but because each die has a different face, there are 5!=120 possible orderings of each hand (Permutations).

HandScoreCountPermutationsOdds
⚀⚁⚂⚃⚄151120120
⚁⚂⚃⚄⚅201120120

Quintuple

There are six possible quintuples, and again, there is only one way to construct each one. While there are 5! possible orderings of five dice, because five of them are interchangeable, there is only one possible ordering of a quintuple (5!/5!=1), which makes a quintuple much less likely than a run of five.

If this seems counter-intuitive, consider rolling one die five times in order. If your first roll is a ⚀, to eventually score quintuples, the next roll must also be a ⚀ (1/6 odds). To eventually score a run of five, the next roll must only be not ⚅ or ⚀ (4/6 odds).

HandScoreCountPermutationsOdds
⚀⚀⚀⚀⚀5111
⚁⚁⚁⚁⚁10111
⚂⚂⚂⚂⚂15111
⚃⚃⚃⚃⚃20111
⚄⚄⚄⚄⚄25111
⚅⚅⚅⚅⚅30111

Run of Three + Double

There are 24 ways to score a run of three + double: 4 runs of three and 6 doubles. Depending on the doubled number, it may be possible to score this as other hands (run of four, triple), but this is never advantageous.

Because of the doubled number, there will be fewer ways to order this hand than a run of five, but more than a quintuple. If the doubled number is in the run, there are 5!/3!=20 possible orderings, and if it is not, then there are 5!2!=60.

HandScoreCountPermutationsOdds
⚀⚁⚂⚀⚀812020
⚀⚁⚂⚁⚁1012020
⚀⚁⚂⚂⚂1212020
⚀⚁⚂⚃⚃1416060
⚀⚁⚂⚄⚄1616060
⚀⚁⚂⚅⚅1816060
⚁⚂⚃⚀⚀1116060
⚁⚂⚃⚁⚁1312020
⚁⚂⚃⚂⚂1512020
⚁⚂⚃⚃⚃1712020
⚁⚂⚃⚄⚄1916060
⚁⚂⚃⚅⚅2116060
⚂⚃⚄⚀⚀1416060
⚂⚃⚄⚁⚁1616060
⚂⚃⚄⚂⚂1812020
⚂⚃⚄⚃⚃2012020
⚂⚃⚄⚄⚄2212020
⚂⚃⚄⚅⚅2416060
⚃⚄⚅⚀⚀1716060
⚃⚄⚅⚁⚁1916060
⚃⚄⚅⚂⚂2116060
⚃⚄⚅⚃⚃2312020
⚃⚄⚅⚄⚄2512020
⚃⚄⚅⚅⚅2712020

Triple + Double

There are 30 ways to score a triple + double: 6 ways to score one and then 5 remaining ways to score the other (to exclude quintuples, which are already accounted for). As with run of three + double, we must account for duplicated numbers when counting orderings. There are then 5!/(3!*2!)=10 permutations of each.

HandScoreCountPermutationsOdds
⚀⚀⚀⚁⚁711010
⚀⚀⚀⚂⚂911010
⚀⚀⚀⚃⚃1111010
⚀⚀⚀⚄⚄1311010
⚀⚀⚀⚅⚅1511010
⚁⚁⚁⚀⚀811010
⚁⚁⚁⚂⚂1211010
⚁⚁⚁⚃⚃1411010
⚁⚁⚁⚄⚄1611010
⚁⚁⚁⚅⚅1811010
⚂⚂⚂⚀⚀1111010
⚂⚂⚂⚁⚁1311010
⚂⚂⚂⚃⚃1711010
⚂⚂⚂⚄⚄1911010
⚂⚂⚂⚅⚅2111010
⚃⚃⚃⚀⚀1411010
⚃⚃⚃⚁⚁1611010
⚃⚃⚃⚂⚂1811010
⚃⚃⚃⚄⚄2211010
⚃⚃⚃⚅⚅2411010
⚄⚄⚄⚀⚀1711010
⚄⚄⚄⚁⚁1911010
⚄⚄⚄⚂⚂2111010
⚄⚄⚄⚃⚃2311010
⚄⚄⚄⚅⚅2711010
⚅⚅⚅⚀⚀2011010
⚅⚅⚅⚁⚁2211010
⚅⚅⚅⚂⚂2411010
⚅⚅⚅⚃⚃2611010
⚅⚅⚅⚄⚄2811010

Hands with One Degree of Freedom

Run of Four

There are three possible runs of four: ⚀⚁⚂⚃x, ⚁⚂⚃⚄x, ⚂⚃⚄⚅x, where x is our “unfixed” die (our degree of freedom). If x is equal to either the highest or lowest element of the run, then we instead have a run of three + double. If it is equal to a number after either end of the run, then we instead have a run of five. So for ⚀⚁⚂⚃x and ⚂⚃⚄⚅x, x has three possible values, and for ⚁⚂⚃⚄x, x has two possible values. We will also consider the cases where x is “inside” the run and “outside” the run separately, as the number of permutations is different.

HandScoreCountPermutationsOdds
⚀⚁⚂⚃x;x∈{⚁,⚂}10260120
⚀⚁⚂⚃x;x=⚅101120120
⚁⚂⚃⚄x;x∈{⚂,⚃}14260120
⚂⚃⚄⚅x;x∈{⚃,⚄}18260120
⚂⚃⚄⚅x;x=1181120120

Quadruple

There are 6 possible quadruples, with 5 ways to construct each one (again, to exclude quintuples). There are 5!/4!=5 permutations of a quadruple.

HandScoreCountPermutationsOdds
⚀⚀⚀⚀x45525
⚁⚁⚁⚁x85525
⚂⚂⚂⚂x125525
⚃⚃⚃⚃x165525
⚄⚄⚄⚄x205525
⚅⚅⚅⚅x245525

Two Doubles

There are 15 ways to score two doubles (half as many as triple + double, because it doesn't matter which number is the first multiple and which number is the second). The unfixed die (x) can take any of the four remaining values2. A hand of two doubles has 120!/(2!*2!)=30 permutations.

HandScoreCountPermutationsOdds
⚀⚀⚁⚁x6430120
⚀⚀⚂⚂x8430120
⚀⚀⚃⚃x10430120
⚀⚀⚄⚄x12430120
⚀⚀⚅⚅x14430120
⚁⚁⚂⚂x10430120
⚁⚁⚃⚃x12430120
⚁⚁⚄⚄x14430120
⚁⚁⚅⚅x16430120
⚂⚂⚃⚃x14430120
⚂⚂⚄⚄x16430120
⚂⚂⚅⚅x18430120
⚃⚃⚄⚄x18430120
⚃⚃⚅⚅x20430120
⚄⚄⚅⚅x22430120

Hands with Two Degrees of Freedom

Run of Three

There are 4 runs of three: ⚀⚁⚂xy, ⚁⚂⚃xy, ⚂⚃⚄xy, ⚃⚄⚅xy. However, x cannot equal y (else we have run of three + doubles), x and y cannot both equal numbers in the run (else we have two doubles), and neither of x and y can equal a fourth part in the run (else we have a run of four).

For a run of three with no duplicates (for example, ⚀⚁⚂⚄⚅), there are 5!=120 permutations. For a run of three with one duplicate, there are 5!/2!=60 permutations.

HandScoreCountPermutationsOdds
⚀⚁⚂xy;x∈{⚀⚁⚂},y∈{⚄⚅}6660360
⚀⚁⚂xy;(x,y)=(⚄,⚅)61120120
⚁⚂⚃xy;x∈{⚁⚂⚃},y=⚅9360180
⚂⚃⚄xy;x∈{⚂⚃⚄},y=⚀12360180
⚃⚄⚅xy;x∈{⚃⚄⚅},y∈{⚀⚁}15660360
⚃⚄⚅xy;(x,y)=(⚀,⚁)151120120

Triple

There are six possible triples, each with two degrees of freedom (x,y). x cannot equal y, neither of x and y can equal the tripled number, and x and y cannot form a run of three with the tripled number. There are then (52-5)/2-R=10-R ways to make each triple, where R is the number of runs of three containing the tripled number.

HandScoreCountPermutationsOdds
⚀⚀⚀xy3920180
⚁⚁⚁xy6820160
⚂⚂⚂xy9720140
⚃⚃⚃xy12720140
⚄⚄⚄xy15820160
⚅⚅⚅xy18920180

Hands with Three Degrees of Freedom

Doubles

There are six possible doubles, each with three degrees of freedom (x,y,z). None of x, y, and z can equal each other, none of x, y, and z can equal the doubled number, and x, y, and z cannot form a run with the tripled number. There are then 5!/(3!*(5-3)!)-R1-R2 =10-R1-R2 ways to make each double, where R1 is the number of runs of three (4) and R2 is the number of runs of four containing the doubled number.

HandScoreCountPermutationsOdds
⚀⚀xyz2560300
⚁⚁xyz4460240
⚂⚂xyz6360180
⚃⚃xyz8360180
⚄⚄xyz10460240
⚅⚅xyz12560300

Other Hands

Other hands are not possible with 5 dice, but I did not bother to prove this more formally. Instead, I can show that all hands are accounted for: there are 6^5=7776 possible rolls (in order), and the sum of all the “Odds” of the above hands is 7776.

Results

Now we can sum the odds by score (instead of by hand) and normalize them. This gives us the following distribution.

ScoreOdds
10
2300
3180
4265
51
6940
710
8355
9330
10741
1180
12915
1340
14620
15791
16405
17100
18760
19140
20296
21140
22160
2330
24105
2521
2610
2730
2810
290
301

The minimum score is 2, maximum 30, mean ~12.4, median 11, and mode 6. My spreadsheet is a bit messy, but you can see it here. Let me know if anything here seems off.


1 “Asked” is a strong word. Nobody asked for this.back

2 In the case of ⚀⚀⚁⚁⚂, both run of three and two doubles would score 6. For convenience, we will consider it as two doubles, because restrictions to exclude it are already part of the math for a run of three.back

Sunday, January 13, 2019

Being Useful

Always feels good to help people with things. Sometimes this is just recommending resources, but sometimes I get to flex my slowly-dying engineer muscles. These are two things I got to help people with recently on some Discord chats, but Discord is temporary so I'm writing them down here for posterity.

RPS Mechanics in Play-by-Post Games

Image source: wikimedia.

Rock-paper-scissors only works in person because you can throw more-or-less simultaneously. In a play-by-post environment, someone has to go first. Here's how:
  1. Alice generates a random number and appends it to her choice.
    Example: "paper04"
  2. Alice takes a hash* of the result and shares it.
    Example: "md5:fbe1a7f5e0330c5cf5a986d40065a21e"
  3. Bob shares his choice.
    Example: "scissors"
  4. Alice shares her original string.
    Example: "paper04"
  5. Bob checks the hash of the original string.
This is not a protocol focused on security. For example, given that the salt is a number 00-99, Bob could generate a rainbow table of all the possible checksums and guess Alice's answer before she revealed it.
It could be automated in some ways if you ran the forum, for example, a bot could automate the final check.




Weighted Selection from a Compact Table

It's common for a table in a book to be formatted like:
1-10. Very common result
11-15. Less common result
16-19. Slightly less common result
20. Very rare result
This is useful if you want to mimic a specific type of distribution given a flat input curve. The theory is that if you use this table a lot, then it will make the results feel more natural.
This presents a problem if you would like to automatically roll on the table in a spreadsheet. A naive way to do this is the format it like:
(A1) Very common result
(A2) Very common result
(A3) Very common result
. . .
(A20) Very rare result
But this is time-consuming and annoying to change. Using VLOOKUP, you can format it like:
(A1) 10 (B1) Very common result
(A2) 15 (B2) Less common result
(A3) 19 (B3) Slightly less common result
(A4) 20 (B4) Very rare result
And then roll as normal. There is a (rough) proof of concept here. There's a couple mistakes in it, but if you play around with it you can see how it works.
Cols A & B are the actual table, while Cols C & D are for illustrative purposes and aren't necessary for the table to function. Cols E & F show how an automated roller might function.
* = I use DuckDuckGo as my default search engine. If you search "md5 [term]" it will auto-suggest the md5sum of "[term]", which is neat. Wolfram Alpha also does this.

Tuesday, March 12, 2013

Cladogram and Notes

I embark upon a new project and shortly thereafter abandon it to the winds, and collect up some random notes I've taken.

An RPG Cladogram

Someone on G+ made the comparison between the proliferation of retroclones and the many distributions of Linux. Inspired by the GNU/Linux Distribution Timeline, I started one for gaming:
It has a couple of problems: one, it's horribly incomplete, and two, it doesn't handle child nodes born after the parent's death very well at all. I think it's a solid idea, and if anyone wants the sources I can send those along (it's just a csv file), but I think I'll let it go until I can work out the child nodes thing.
There is some precedent for this:

Notes

  • An impromptu mechanic I was proud of: you have a keyring. Each round, you try a key. Roll 1d12 on a 1, it fits. Next round, on a 1-2 it fits. The round after on a 1-3, and so on.
  • A pop-o-matic should be a very fair way of rolling dice. If it isn't though, it might be modelled best as a Markov process.
  • I've been playing Bang! with some people. Our group tends to be small though, so that any weapon will do just as good as another. To fix this, I propose that people can only fire in one direction, like an M. C. Escher staircase.
  • Mr. Sivaranjan comments that it's about a 50% probability to roll under a random ability score. I had thought it would be exactly 50% to roll under an ability score (inclusive), but AnyDice says 52.5%. I'll have to figure that one out when I've got more time. Unsurprisingly, the distribution of wild talents follows an inverse normal curve, shown below.

Monday, September 17, 2012

Non-transitive Dice with Cards

Non-transitive dice are a fascinating phenomenon. However, I don't really want to buy more dice*, especially dice that look, at a glance, like all my other dice. So I've been trying to think up a way to have non-transitive dice without actually needing new dice.

Example of non-transitive dice (opposite sides are same) (Image Source: Wikimedia Commons).

By far the simplest thing I've found, is to make each "die" from a stack of playing cards. This has several advantages:
  • If all piles are the same size, then they will appear identical when face-down. This means that each pile can be chosen with incomplete knowledge or assigned at random.
  • As cards are played, they may be discarded by some rule. Thus, while the stacks may initially be non-transitive, their relation can change over the course of a game.
  • Playing cards are readily available, and can be used to emulate any set of dice that doesn't need numbers higher than 13.

I don't personally have a use for them yet, but if you come up with one I'd love to know.

* = This is a lie.

Tuesday, August 21, 2012

Modular Dice

I've been using "d50"s without noticing for some time. You can get huge, strange 50-sided dice, but that's not what I'm talking about. Instead, I roll d% and if the tens-place is greater than 5, I "wrap around". I'm sure this is something that's not uncommon, it saves re-rolling if the die is an even multiple.

I decided to investigate this further. For a uniform distribution it's not that interesting, but starting from a normal distribution it's a neat way to get two peaks. Figure 1 shows the effects of different moduli on the 3d6 distribution.

Figure 1
If you'd like to play with this in anydice here's the function I've written:
function: A:n mod B:n {
    if A > B {result: [(A - B) mod B]}
    result: A
}