0.1.0 • Published 1 year ago
fuzzy-boolean v0.1.0
fuzzy-boolean
This package contains the class FuzzyBoolean
that uses a truth value between 0 and 1, and returns a random boolean in valueOf()
that varies depending on the current truth value.
Install
npm install fuzzy-boolean
Fields and Methods
FuzzyBoolean
class :
truth_value
: The truth value of the fuzzy booleanconstructor(truth_value=0.5)
- Boolean returners :
valueOf()
: Returns a random boolean, withtruth_value
being the probability of returningtrue
realBoolean()
: Returns the strict boolean equivalent,null
otherwiseclosestBoolean()
: Returns the boolean that corresponds the most (Iftruth_value
is one-half, returnstrue
)
- Operations :
not()
,and(value)
,or(value)
,xor(value)
,min(value)
,max(value)
,add(value)
,sub(value)
,btw(value)
Values are automatically transformed into FuzzyBoolean
if it's not already the case.
Example
var FuzzyBoolean = require('fuzzy-boolean');
var heroHP = 200;
var enemyHP = 200;
var criticalHit = new FuzzyBoolean(0.4);
var useEffect = new FuzzyBoolean(0.25);
while (heroHP > 0) {
console.log("Hero: " + heroHP + " HP, Enemy: " + enemyHP + " HP");
var damages = 25 + criticalHit * 15;
enemyHP -= damages;
console.log("Your enemy lost " + damages + " HP");
if (enemyHP <= 0) {
console.log("");
break;
}
// You can't use a fuzzy boolean alone, because it would return the object instead of the value given by valueOf()
// You can instead do useEfect==true, useEffect&true, useEffect^false, useEffect.valueOf(), etc.
if (useEffect == true) {
console.log("The enemy used an effect");
criticalHit = criticalHit.and(0.5);
console.log("Critical hits will now occur 50% less frequently");
}
heroHP -= 30;
console.log("You lost 30 HP");
console.log("");
}
if (heroHP > 0) console.log("You won!");
else console.log("You lost...");
License
0.1.0
1 year ago