一个解析和评估d&d启发的roll表达式的引擎

dndice的Python项目详细描述


滚动

PyPI versionDocumentation Status

这个包处理的是roll表达式,其灵感来自于d&d使用的语法。 最基本的是,有类似1d20的表达式,意思是“滚动一个20边的模具”。 D&D在添加修饰符时停止,例如1d6+2。 这个包将与它一起运行,并将这些骰子表达式引入到整个算术框架中。 你可以加,减,乘,甚至指数滚动在一起,更不用说所有的滚动特定的操作,如采取最高或最低滚动或重新滚动给定的条件。 由于这些都是数学表达式,就像普通表达式一样,请注意,它们可能会变得任意复杂。 唯一的限制是python可以为计算(9^9^9^9^9)d10000或类似的荒谬表达式带来多少资源。

下面是支持哪些运算符以及它们所做操作的完整说明。

OperatorFormatMeaning
!x!Calculate the factorial of x.
dxdyTake a y-sided die and roll x of them. y can be an integer, and works just as you would expect. It can also be a list of arbitrary numbers (delineated by ^{} and separated with commas), in which case it works as a die with one side labeled with each number in the list.
daxdayTake a y-sided die and return the average as if x of them had been rolled. This returns an unrounded number.
dcxdcyRoll a critical hit, where the number of dice rolled is doubled.
dmxdmyRoll the maximum on every die rolled.
hROLLhnAfter making a roll, discard all but the highest n of the rolls. Hint: 2d20h1 is advantage.
lROLLlnAfter making a roll, discard all but the lowest n of the rolls. Hint: 2d20l1 is disadvantage.
fROLLfnAfter making a roll, treat any value that is less than n as n.
cROLLcnAfter making a roll, treat any value that is greater than n as n.
r or roROLLronAfter making a roll, look at all of them and reroll any that are equal to n, reroll those, and take the result.
R or RoROLLRonAfter making a roll, look at all of them and reroll any that are equal to n and reroll those. If that number comes up again, continue rerolling until you get something different.
r> or rhROLLrhnAfter making a roll, look at all of them and reroll any that are strictly greater than n, reroll those, and take the result.
R> or RhROLLRhnAfter making a roll, look at all of them and reroll any that are greater than n and reroll those. If a number greater than n comes up again, continue rerolling until you get something different.
r< or rlROLLrlnAfter making a roll, look at all of them and reroll any that are strictly less than n, reroll those, and take the result.
R< or RlROLLRlnAfter making a roll, look at all of them and reroll any that are less than n and reroll those. If a number less than n comes up again, continue rerolling until you get something different.
tROLLtnAfter making the roll, count the number of rolls that were at least n.
TROLLTnAfter making the roll, count the number of rolls that were at most n.
^x^yRaise x to the y power. This operation is right-associative, meaning that the right side of the expression is evaluated before the left. This really only comes up when chained, for example in ^{}. This would not be ^{}, but rather ^{}.
*x*yx times y.
/x/yx divided by y. This returns an unrounded number.
%x%yx modulo y. That is, the remainder after x is divided by y.
+x+yx plus y.
-x-yx minus y.
> or gtx>yCheck if x is greater than y. Returns a 1 for yes and 0 for no.
>= or gex>=yCheck if x is greater than or equal to y. Returns a 1 for yes and 0 for no.
< or ltx<yCheck if x is less than y. Returns a 1 for yes and 0 for no.
<= or lex<=yCheck if x is less than or equal to y. Returns a 1 for yes and 0 for no.
=x=yCheck if x is equal to y. Returns a 1 for yes and 0 for no.
&x&yCheck if x and y are both nonzero.
|x|yCheck if at least one of x or y is nonzero.

使用此软件包

作为用户或玩家

从pypi安装这个包还将把脚本roll安装到您的路径。这是一个简单的命令行脚本,允许您使用这个包的所有功能。 对于同样的gui,请查看我的存储库DnD,这是一个围绕d&d 5e的大型项目,允许您跟踪您的角色和怪物。

作为开发人员

由于根目录中的__init__.py文件,整个存储库可以用作包。 这将在顶层公开包的所有有用内容,以便您可以在任何需要访问的位置克隆此存储库。 当然,您也可以像平常一样通过PyPI将其作为标准python包安装

安装poetry进行依赖项管理。没有运行时依赖项,唯一的开发依赖项是文档的sphinx和测试的nose2

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

推荐PyPI第三方库


热门话题
将中心面板添加到“我的内容”窗格时,java GUI对象消失   java无法更新oracle中的clob字段   php Linux+动态插入的Java小程序=在NPObject上调用方法时出错   java JVisualVM探查器代理jar已加载,但代理初始化失败   java Android在运算符和TextView值方面存在问题   用于OpenPGP智能卡小程序的rsa解密APDU   Java GUI按钮不会添加到面板中   java找不到移动图像(或其他可单击对象)的方法   java中Do/While循环的问题   多线程使java程序在没有线程的情况下休眠   java如何在Webflux功能端点的测试中禁用Spring安全性   如果存在后退历史记录,则java WebView仅显示后退按钮   通过USB将Arduino中显示的java错误数据传输到Android   java如何使用安卓 studio从4层父节点firebase获取子节点数据   jpanel中JLabel的java搜索栏   来自gallery/camera的java Android图像预览不同