5
\$\begingroup\$

I'm trying to work out the Probability of reaching a total with a custom die system.

Each die in this system has 6 sides: 1 Sword, 2 Sword, 3 Sword, Political, Castle, and Wizard.

Each player starts off with 7 such dice. On their turn, they can purchase cards from a central Supply if they manage to roll a total specified on the card. An example would be the Priest card which requires a player to get 4 Swords, 1 Sword, 1 Political, and 1 Castle. A player would declare that they will try to purchase this card, then roll their dice. They would try to combine dice to meet the 4 swords requirement, and/or spend dice to meet any other requirement listed. The order the requirements are met in does not matter. After spending as many dice as the player wants to, with no minimum, the player would reroll all remaining dice not spent to meet requirements and try again if they had not yet met all requirements. If no requirements were met this round, a 1 die penalty is paid by the player. Dice cannot be reserved across rounds.

I am interested in finding a way to quickly calculate the odds of successfully being able to buy a card on a turn given the cost of that card.

An example of an unsuccessful purchase would be:

1) The player declares they wish to buy the Priest card

2) The player rolls 1 Sword, 1 Sword, Political, Political, 3 Swords, Castle, 2 Swords.

3) They choose to place 1 Sword to meet the 1 Sword requirement, 3 swords and the other 1 Sword to meet the 4 swords requirement, choose not to spend any of the politicals to meet the Political requirement (no reason, just cause) and reroll now 4 dice as three are placed on the Priest Card fulfilling requirements.

The next rolls are all swords, so the player loses a single Dice and rerolls 3.

They get 3 political and so take one to complete the political requirement leaving 2 to play.

They roll, getting a 3-Swords and a Wizard, and so lose a die.

They roll, getting a 2-Swords, and fail to complete the requirements.

There are other mechanics in play with cards that alter conditions but I just need help with this aspect.

Been trying to use AnyDice and not having any real successes as examples and tweaks to existing code gives errors.

Again, I'm trying to quickly calculate probabilities of being able to purchase a card on a single turn given its price.

I'm intending to use this mechanic first in a card game and then to scale it up for use as the mechanics behind an RPG system.

\$\endgroup\$
  • \$\begingroup\$ Comments are not for extended discussion about program implementations; that conversation has been moved to chat. \$\endgroup\$ – SevenSidedDie Jul 9 '17 at 17:41
  • 1
    \$\begingroup\$ Your example could probably do to be improved a bit, as the player could have bought it outright with their original roll. It's conceivable that a player might have held back on assigning, say, a 1 sword under the theory that they'd be likely to get a sword later, and it would help with rolling other results in the meantime. Choosing to simply not grab victory when victory was offered, however, suggests a player who doesn't actually care about winning. \$\endgroup\$ – Ben Barden Jul 10 '17 at 13:09
  • 1
    \$\begingroup\$ The answer to this question will change depending on the strategy of the player. Do they take a "greedy" approach and use all available dice, even at surplus (so they always cash in 3 Swords + 3 Swords for a 4 Swords requirement)? Or do they reject imperfect results to gamble for finding a perfect fit (they don't ever take a 4 Swords card if they don't roll exactly 4 Swords)? Or are they allowed to change their mind according to their strategy? \$\endgroup\$ – user27327 Jul 11 '17 at 15:46
  • 1
    \$\begingroup\$ I've realized this Q is a bit like asking, "I'm new to poker, what are my chances of winning?" You should define a strategy to evaluate the probability for. Otherwise there is no singular result to this Q. Different strategies will have different chances of being successful. \$\endgroup\$ – user27327 Jul 11 '17 at 15:47
  • 1
    \$\begingroup\$ This may be more appropriate in another exchange. If you post this to another exchange though, I'd reduce the example to a barebones example. "I have these dice. I roll the dice this many times. I need to roll this. How do I calculate the probability of rolling the needed results" \$\endgroup\$ – Bryant Jackson Jul 14 '17 at 20:50
4
\$\begingroup\$

There is a dice game almost exactly like what you're describing called Farkle. Farkle is a game where you try to make certain combinations of dice and when you make a combo, the dice involved are "locked in" removed from your rolling pool. As long as you make at least one scoring roll and lock in that score, you can keep rolling any dice that have not been locked in yet. Instead of scores, your game has costs for cards, but this doesn't change the math.

Here are some good articles about scoring and probability for Farkle:

https://graciesdad.wordpress.com/2009/08/30/farkle-odds/

http://www.jonmutchler.com/FarkleFun2.html

The word "Farkle" refers to "failed to score on a roll". So when you see "probability to Farkle," they are talking about the probability of rolling dice in a way that nothing can be locked in, at which point the player must stop rolling. 1 - P(farkle) = probability to score and keep rolling.

All you would have to do is replace the table of possible scores with the costs associated with your cards and map each side of your game's dice to 1-6 (e.g. "1-3 Sword" is 1-3, Political = 4, Castle = 5, Wizard = 6). The differences you have to account for is that Farkle is played with 6 dice and your game is played with 7, and that in Farkle a single 1 or 5 is a scoring roll, where in your game, a roll that contributes to the cost of a card is a scoring roll; so your "P(farkle)" changes based on the card being rolled for.

If you need help converting a 6-dice game to a 7-dice game, that's a separate question but I can try to help with that, too. Alternatively (if it doesn't break your game), you can make your game a 6-dice game and port it directly, reducing the costs of all of your cards by 1 to account for less dice.

\$\endgroup\$
  • \$\begingroup\$ Weirdly farkle is where one got the initial idea for the game from, and developed it for a new system as it offered interesting dice mechanics. \$\endgroup\$ – user37069 Jul 16 '17 at 16:41
  • \$\begingroup\$ Is there a reason you don't want to just reskin Farkle into your game? Why the extra dice? \$\endgroup\$ – Eldritch Arbalest Jul 18 '17 at 18:25
  • \$\begingroup\$ From tinkering around 7 dice works well with decreasing dice as it hold the game about the right amount of time per round. \$\endgroup\$ – user37069 Jul 19 '17 at 17:10
4
\$\begingroup\$

I've coded up an incomplete simulation of your rule set in Python. From my strategy, it looks like about an eighty percent chance of buying the Priest card with seven dice. I've tested the code on TiO so you can run it without installing Python locally.

Here's an example of the debug output:

Reqs: [Sword_4, Sword_1, Political, Castle]
Rolls: [Wizard, Sword_1, Sword_3, Sword_1, Castle, Wizard, Sword_1]
Matched: Castle
4 matched by 3, 1
Sword_1 Matched exactly
No matches with: [Wizard, Sword_1, Wizard, Sword_1], still need [Political]
Rerolling 4
Reqs: [Political]
Rolls: [Castle, Wizard, Sword_3, Castle]
Current Matches: [Castle, Sword_3, Sword_1, Sword_1]
No matches with: [Castle, Wizard, Sword_3, Castle], still need [Political]
Rerolling 3
Reqs: [Political]
Rolls: [Sword_2, Sword_1, Sword_3]
Current Matches: [Castle, Sword_3, Sword_1, Sword_1]
No matches with: [Sword_2, Sword_1, Sword_3], still need [Political]
Rerolling 1
Reqs: [Political]
Rolls: [Sword_3]
Current Matches: [Castle, Sword_3, Sword_1, Sword_1]
No matches with: [Sword_3], still need [Political]
Rerolling -2
Failed to acquire Priest remaining:
Chance to buy card Priest is about 78.39% after 10000 iterations

Here's a successful attempt:

Reqs: [Sword_4, Sword_1, Political, Castle]
Rolls: [Castle, Sword_1, Sword_1, Wizard, Sword_1, Sword_1, Sword_3]
Matched: Castle
4 matched by 3, 1
Sword_1 Matched exactly
No matches with: [Sword_1, Wizard, Sword_1, Sword_1], still need [Political]
Rerolling 4
Reqs: [Political]
Rolls: [Political, Sword_2, Castle, Sword_1]
Current Matches: [Castle, Sword_3, Sword_1, Sword_1]
Matched: Political
Unneeded: [Sword_2, Castle, Sword_1]
Successfully acquired Priest

You can define new cards by modifying the line:

priest = card("Priest", dice.Sword_4, dice.Sword_1, dice.Political, dice.Castle)

Apologies for the verbosity, I was making sure that the strategy was working properly.

One example where my implementation falls short is failing to match a Sword 4 with a Sword 2 and two Sword 1s. That it relatively trivial to add, but it's probably something you'd choose if the Sword 4 was your only remaining requirement.

Actually, I just reviewed your rules and I've implemented the penalties wrong. I've just given the first re-roll free and added an increasing penalty for each subsequent round. It is relatively simple to track the matches within a round and apply penalties then, I suspect it'll make things easier to recruit the Priest.

Let me know if this approach is interesting or useful and I'll fix it up or feel free to give it a go yourself.

Edit: Okay, it was gnawing at me so I fixed the implementation here. As suspected the chance to acquire a Priest increases, to about eighty-five percent. Here's a new log showing an example including rerolls:

Reqs: [Sword_4, Sword_1, Political, Castle]
Rolls: [Sword_1, Sword_1, Wizard, Sword_1, Wizard, Sword_2, Wizard]
Sword_1 Matched exactly
No matches with: [Sword_1, Sword_1, Wizard, Sword_1, Wizard, Sword_2, Wizard], still need [Sword_4, Political, Castle]
Rerolling 7
Reqs: [Sword_4, Political, Castle]
Rolls: [Castle, Castle, Wizard, Sword_2, Castle, Sword_2, Sword_1]
Current Matches: [Sword_1]
Matched: Castle
4 matched by 2, 2
No matches with: [Castle, Wizard, Castle, Sword_1], still need [Political]
Rerolling 4
Reqs: [Political]
Rolls: [Sword_3, Sword_1, Sword_1, Sword_2]
Current Matches: [Sword_1, Castle, Sword_2, Sword_2]
No matches with: [Sword_3, Sword_1, Sword_1, Sword_2], still need [Political]
Rerolling 3
Reqs: [Political]
Rolls: [Sword_2, Sword_3, Political]
Current Matches: [Sword_1, Castle, Sword_2, Sword_2]
Matched: Political
Unneeded: [Sword_2, Sword_3]
Successfully acquired Priest

Unfortunately this shows another problem, I wasn't removing the sword dice from the pool when it matched exactly. Also I wasn't allowing two Sword 3s to fulfil a Sword 4 requirement. A quick fix here which gets us back around to an eighty-one percent chance to acquire the Priest.

Here's a failed acquisition attempt which looks correct:

Reqs: [Sword_4, Sword_1, Political, Castle]
Rolls: [Wizard, Sword_1, Sword_1, Sword_1, Sword_2, Political, Wizard]
Matched: Political
Sword_1 Matched exactly
No more matches with: [Wizard, Sword_1, Sword_1, Sword_2, Wizard], still need [Sword_4, Castle]
Rerolling 5
Reqs: [Sword_4, Castle]
Rolls: [Sword_1, Wizard, Sword_1, Castle, Wizard]
Current Matches: [Political, Sword_1]
Matched: Castle
No more matches with: [Sword_1, Wizard, Sword_1, Wizard], still need [Sword_4]
Rerolling 4
Reqs: [Sword_4]
Rolls: [Sword_1, Political, Sword_1, Political]
Current Matches: [Political, Sword_1, Castle]
No more matches with: [Sword_1, Political, Sword_1, Political], still need [Sword_4]
Rerolling 3
Reqs: [Sword_4]
Rolls: [Political, Political, Sword_3]
Current Matches: [Political, Sword_1, Castle]
No more matches with: [Political, Political, Sword_3], still need [Sword_4]
Rerolling 2
Reqs: [Sword_4]
Rolls: [Sword_3, Castle]
Current Matches: [Political, Sword_1, Castle]
No more matches with: [Sword_3, Castle], still need [Sword_4]
Rerolling 1
Reqs: [Sword_4]
Rolls: [Sword_3]
Current Matches: [Political, Sword_1, Castle]
No more matches with: [Sword_3], still need [Sword_4]
Rerolling 0
Failed to acquire Priest remaining:

Although it does show that perhaps I should have included the 2,1,1 match for Sword 4.

Last Edit: Okay I've made some modifications and now the code supports arbitrary Sword requirements up to twelve. It was a little finicky to get working correctly and my generic sword matching algorithm isn't quite as good as the manual implementation - 36.5% compared to 40% for 3 Sword_4 requirements. One failure of my generic algorithm is that it will match four 1 Swords to a 4 Swords requirement, even if there are additional Sword requirements. I doubt that's the entire cause of the discrepancy.

In any case the code is available here.

The chance to acquire a card with a requirement of 12 Swords is about 11.5% when rolling seven dice.

\$\endgroup\$
  • \$\begingroup\$ Do not know how to thank you, wow. Would this work with say sword 12 requirement on cards?? \$\endgroup\$ – user37069 Jul 19 '17 at 17:55
  • \$\begingroup\$ The code doesn't sensibly use Sword values to match the requirement, there are just special rules to handle the numeric implications (e.g. 2,2 matching 4). The code will support a card requirement of three Sword_4s if that helps. Chance is just under forty percent to acquire. \$\endgroup\$ – Eric Jul 19 '17 at 22:33
  • \$\begingroup\$ Thanks can work with that, really blew me away you managed this. Appreciated. \$\endgroup\$ – user37069 Jul 19 '17 at 23:14
  • \$\begingroup\$ You piqued my interest and I was happy to get it working. The code could be modified to work with arbitrary sword values if you wanted although it'd have to be refactored to sensibly use the numeric values of the swords. Unfortunately, you'd also have to encode some strategic decisions - e.g. use 2,2,1 to match a 5 only if that's the last requirement. Also your previous comment raised the question, if you roll a Sword 3 and a Castle and need to match a Sword 4, can you allocate the Sword 3 and then re-roll the Castle? Your other comments imply no, but partial matches are required for Sword 7+ \$\endgroup\$ – Eric Jul 20 '17 at 1:16
  • \$\begingroup\$ If you have a sword requirement of 4 you would need to roll 4+ Swords on a single roll turn, so if you had 6 dice left you would need to roll 4+ on that roll, if you roll less than 4+ then you lose a dice and reroll 5+ dice and need to try and roll 4+ dice, so if you rolled a 2 dice, 1 dice and 3 castles this would not be enough, and they would have to re-roll losing again one dice. You need to fulfil one of the requirements in one roll. I.e 3 swords, or 4 swords or 4 Castles or 2 Political, etc \$\endgroup\$ – user37069 Jul 22 '17 at 13:15
-5
\$\begingroup\$

I reccommend using the website AnyDice to simulate outcomes. You'll need to read the documentation a bit to figure out what to do, but this will be the best way to effectively simulate what you're looking for. Pay special attention to the section on Arbitrary Dice, which will allow you to create the specific dice you're looking for, though keep in mind you're effectively using d6 at all times in this example.

The articles section also has some great information about different programs for in-depth analysis that may be useful to you.

\$\endgroup\$
  • 3
    \$\begingroup\$ The question already states the asker has been trying to use anydice to model this with little success; reiterating "try anydice, read the docs!" is not a helpful answer. If you can specifically point to examples which help them to model their rules, that would improve the answer. Aside: prior investigation in the comments (now moved to chat) makes it quite clear this is not a trivial problem for anydice to solve, if it is indeed a problem that anydice can solve; certainly it's well beyond the documentation that anydice has. \$\endgroup\$ – Carcer Jul 14 '17 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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