AKDice 3.1.5.8
See the version list below for details.
dotnet add package AKDice --version 3.1.5.8
NuGet\Install-Package AKDice -Version 3.1.5.8
<PackageReference Include="AKDice" Version="3.1.5.8" />
paket add AKDice --version 3.1.5.8
#r "nuget: AKDice, 3.1.5.8"
// Install AKDice as a Cake Addin
#addin nuget:?package=AKDice&version=3.1.5.8
// Install AKDice as a Cake Tool
#tool nuget:?package=AKDice&version=3.1.5.8
AKDice 3.1.x
Using
using Anikaiful.Dice;
Notes
All "probability values" are automatically clamped into (0 .. 100, inclusive) range unless Dice.ThrowProbabilityOutOfRange = true
is set.
Static Functions
double Dice.Range(double d1, double d2)
Returns a double
in range (d1
.. d2
, inclusive). Note that it doesn't matter which of the numbers is greater than the other.
int Dice.Range(int i1, int i2)
Returns an int
in range (i1
.. i2
, inclusive). Note that it doesn't matter which of the numbers is greater than the other.
bool Dice.ToBoolean(bool? b)
Returns either b
(if not null
) or a random true
|false
value.
bool Dice.Chance(int probability = 50)
Returns true
if a random black-box roll with given probability
so dictates, otherwise false
.
Extensions to int
#
represents any valid int
value (constant or otherwise), e.g. in form 5.d6()
or (x+y*z).d20()
. Result of these extensions depends on probability
; return is either the result of the roll or 0 (zero). mod
value is applied to final result (if probability
doesn't clamp the result to zero).
int #.d2(int mod=0, int probability=100)
... toss an imaginary D2 (or basically a coin?).int #.d3(int mod=0, int probability=100)
... toss an imaginary D3 (more or less equivalent to D6/2 with real dice).int #.d4(int mod=0, int probability=100)
... toss a D4.int #.d5(int mod=0, int probability=100)
... toss an imaginary D5 (more or less equivalent to D10/2 with real dice).int #.d6(int mod=0, int probability=100)
... toss a D6.int #.d8(int mod=0, int probability=100)
... toss a D8.int #.d10(int mod=0, int probability=100)
... toss a D10.int #.d12(int mod=0, int probability=100)
... toss a D12.int #.d20(int mod=0, int probability=100)
... toss a D20.int #.d100(int mod=0, int probability=100)
... toss a D100 (yea, these dice do exist, too).
Internally the above extensions refer to...
int #.Probability(int probability, int otherwise=0)
... which returns either#
itself orotherwise
, depending.
Extensions to bool
#
refers to any valid bool
value.
bool #.Probability(int probability)
... return#
ifprobability
so dictates, otherwise!#
.
Extensions to string
#
refers to any valid string
value.
string #.Evaluate(Dice.RollEvaluateMethod method = Dice.RollEvaluateMethod.Default)
Evaluates all dice roll expressions and/or simple calculation ops (plus, minus, multiply, divide) embedded in the free-form string#
, returning a new string. By defaultDice.RollEvaluateMethod.Default
is used asmethod
. At times you might need minimum/maximum value of the expression(s), and for that purpose there isDice.RollEvaluateMethod.Minimize
andDice.RollEvaluateMethod.Maximize
respectively. Note that multiply and divide work internally withdouble
values and thus YMMV with their result precision.T #.Evaluate
<T
>(Dice.RollEvaluateMethod method = Dice.RollEvaluateMethod.Default)
As per#.Evaluate()
but with result represented asT
. Note that this will work (only) whenT
is:int
,long
,float
,double
,decimal
.T #.Maximize
<T
>()
As per#.Evaluate
<T
>()
but with result maximized.T #.Minimize
<T
>()
As per#.Evaluate
<T
>()
but with result minimized.
Examples
var a = 3.d6(); // throw 3d6
var b = 4.d4(3); // throw 4d4+3
var c = true.Probability(35); // 35% probability to result in "true", 65% "false"
var d = (a+b).d8(probability: 75); // 75% probability to result in "(a+b)d8", 25% in zero.
var s = "This string contains dice expression 18d7+8 and so on.".Evaluate();
// s = "This string contains dice expression # and so on.", where # is the result of 18d7+8.
var l = "5d10+5".Minimize<int>(); // l == 10
var m = "5d10+5".Maximize<int>(); // m == 55
TODO, etc.
- Get
#.Evaluate()
to work with various forms of probability expressions.
Changes from 3.1.4 to 3.1.5
- Added "generics" Evaluate() to string extensions (mainly for syntax sugar).
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.1.5.11 | 498 | 4/21/2022 |