模拟各种掷骰子的情况
dice-sim的Python项目详细描述
简介
用掷骰子进行模拟的小脚本,包括 在这种情况下,你可以得到多个重掷骰子并决定要投哪一个骰子 保持或重新滚动。
用法
usage: dice.py [-h] [-n NUM] [-s SIDES] [-ss [SIDES [SIDES ...]]] [-r REROLL] [--keep [STRATEGY [STRATEGY ...]]] [--stats [REDUCE [REDUCE ...]]] [-N SIMULATIONS] [--counts] Simulate various dice throw situations. optional arguments: -h, --help Show this help message and exit. -n NUM Specify the number of dice to throw. -s SIDES Specify the number of sides all dice have. -ss [SIDES [SIDES ...]] Specify the number of sides for each individual die. -r REROLL Perform multiple rerolls (stats only count last roll). --keep [STRATEGY [STRATEGY ...]] Choose a keeping strategy when performing rerolls. Options are: ['none', 'unique', 'duplicate', 'value']. --stats [REDUCE [REDUCE ...]] Performs multiple throws and outputs cumulative results. Provide a parameter to choose an approach for reducing a dice throw to a single value of interest. Options are: ['count', 'sum', 'unique', 'values', 'order']. -N SIMULATIONS Set the number of simulations to run for statistical results. --counts Print actual event counts instead of percentages in the statistical results.
示例
./dice.py [6] ./dice.py -n 2 [6, 5] ./dice.py -n 2 --stats sum Total sum of dice values in a throw: 2: 2.50 % 3: 4.50 % 4: 7.70 % 5: 11.20 % 6: 14.70 % 7: 19.20 % 8: 13.40 % 9: 9.80 % 10: 8.40 % 11: 5.60 % 12: 3.00 % ./dice.py -n 2 --stats count 1 6 Number of dice with the value [1, 6]: 0: 44.80 % 1: 43.60 % 2: 11.60 % ./dice.py -n 6 -r 3 [6, 5, 3, 2, 4, 3] [5, 2, 3, 4, 6, 4] [2, 5, 4, 2, 6, 6] ./dice.py -n 6 -r 3 --keep value 3 [6, 5, 3, 2, 4, 3] [3, 3, 5, 2, 3, 4] [3, 3, 3, 6, 4, 2] ./dice.py -n 6 -r 3 --keep value 3 --stats count 3 Number of dice with the value [3]: 0: 4.50 % 1: 16.30 % 2: 26.70 % 3: 31.20 % 4: 15.70 % 5: 5.10 % 6: 0.50 %
术语
- 保持策略:用来决定在两个骰子之间保持哪一个骰子的策略 重新滚动
- 还原函数:将掷骰子结果还原为 单一利息价值