模拟各种掷骰子的情况

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 %

术语

  • 保持策略:用来决定在两个骰子之间保持哪一个骰子的策略 重新滚动
  • 还原函数:将掷骰子结果还原为 单一利息价值

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Android:在ListView上使用setOnItemClickListener   使用Netbeans 7.0连接到SQL Server的java正在挂起   java Spring3依赖项注入不适用于mule   java Flink SQL结果字段与LocalDateTime上请求的类型错误不匹配   java找不到文件的结尾   考虑到NamingStrategy,java有没有办法将字符串转换为JsonNode?   使用Netbeans/ant部署java(命令行)应用程序   java如何修复Spring引导多部分上载中的“所需请求部分不存在”   java在应用程序启动时通过引用获取映射未知目标实体属性异常   java形状旋转问题Java2d   Weblogic服务器上的java ExecuteAndWaitInterceptor问题   JavaSpringBoot:project将图像保存在错误的路径中,并且在使用IDEIntellji打开时不显示图像   类向java接口添加方法   Swing组件上的Java 7泛型   sql server如何从java获取用户名。sql。联系   java如何检查该行是否与正则表达式(regex)冲突?   java如何在spring引导安全中为计数失败登录设置验证登录为false   图像如何在Java中使PNG的白色透明?