Skip to content

Instantly share code, notes, and snippets.

@qguv
Created December 17, 2018 20:48
Show Gist options
  • Save qguv/fec5a236c4455b81afad9a536d0235dd to your computer and use it in GitHub Desktop.
Save qguv/fec5a236c4455b81afad9a536d0235dd to your computer and use it in GitHub Desktop.
Calculate chance of success in an Arkham attack roll using brute force
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Arkham Successes\n",
"_Calculate chance of success in an Arkham attack roll using brute force._"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" [- CURSED -] | [- NORMAL -] | [- BLESSED -]\n",
" | |\n",
" successes | successes | successes\n",
"dice 1 2 3 | dice 1 2 3 | dice 1 2 3\n",
" 1 17% - - | 1 33% - - | 1 50% - - \n",
" 2 31% 3% - | 2 56% 11% - | 2 75% 25% - \n",
" 3 42% 7% 0% | 3 70% 26% 4% | 3 88% 50% 12%\n",
" 4 52% 13% 2% | 4 80% 41% 11% | 4 94% 69% 31%\n",
" 5 60% 20% 4% | 5 87% 54% 21% | 5 97% 81% 50%\n",
" 6 67% 26% 6% | 6 91% 65% 32% | 6 98% 89% 66%\n"
]
}
],
"source": [
"from itertools import product\n",
"\n",
"# the most concurrent successes required in the game\n",
"MAX_SUCCESSES_NEEDED = 3\n",
"\n",
"# table headers\n",
"print(\" [- CURSED -] | [- NORMAL -] | [- BLESSED -]\")\n",
"print(\" | |\")\n",
"print(\" successes | successes | successes\")\n",
"print(\"dice 1 2 3 | dice 1 2 3 | dice 1 2 3\")\n",
"\n",
"for n_dice in range(1, 7):\n",
" total = 0\n",
" \n",
" # used to count number of wins at various difficulties\n",
" # incrementing value at i means: we've won a roll where i successes are required\n",
" cursed_wins = [0] * (MAX_SUCCESSES_NEEDED + 1)\n",
" normal_wins = [0] * (MAX_SUCCESSES_NEEDED + 1)\n",
" blessed_wins = [0] * (MAX_SUCCESSES_NEEDED + 1)\n",
"\n",
" # roll n_dice number of d6\n",
" for roll in product(range(1, 7), repeat=n_dice):\n",
" total += 1\n",
"\n",
" # count how many of each value we got\n",
" counts = [0] * 7\n",
" for die in roll:\n",
" counts[die] += 1\n",
"\n",
" # see how many successes we got\n",
" for successes_needed in range(1, MAX_SUCCESSES_NEEDED + 1):\n",
" if counts[6] >= successes_needed:\n",
" cursed_wins[successes_needed] += 1\n",
" if sum(counts[5:]) >= successes_needed:\n",
" normal_wins[successes_needed] += 1\n",
" if sum(counts[4:]) >= successes_needed:\n",
" blessed_wins[successes_needed] += 1\n",
"\n",
" # print table\n",
" for i, wins in enumerate((cursed_wins, normal_wins, blessed_wins)):\n",
" if i != 0:\n",
" print(' | ', end='')\n",
" print(' ', n_dice, ' ', end='')\n",
" print(*(' - ' if x == 0 else \"{:3.0%}\".format(x / total) for x in wins[1:]), end='')\n",
" print()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
@qguv
Copy link
Author

qguv commented Dec 17, 2018

Github will display the interpreted Jupyter notebook on the desktop site. For mobile and noscript users, here's the output:

  [- CURSED -]   |   [- NORMAL -]   |  [- BLESSED -]
                 |                  |
      successes  |       successes  |       successes
dice  1   2   3  | dice  1   2   3  | dice  1   2   3
  1  17%  -   -  |   1  33%  -   -  |   1  50%  -   - 
  2  31%  3%  -  |   2  56% 11%  -  |   2  75% 25%  - 
  3  42%  7%  0% |   3  70% 26%  4% |   3  88% 50% 12%
  4  52% 13%  2% |   4  80% 41% 11% |   4  94% 69% 31%
  5  60% 20%  4% |   5  87% 54% 21% |   5  97% 81% 50%
  6  67% 26%  6% |   6  91% 65% 32% |   6  98% 89% 66%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment