Skip to content

phil-r/unfair-dice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

(Un)fair dice

Dice that protects you from time travelers!

Description

Imagine a simple coin. Is it possible to always get heads? Yes! Well.. if you can time travel of course, just travel back and re-roll until you get heads(in computer gaming it's called save scumming), continue ad infinitum.

To solve this problem (un)fair dice was invented! It keeps track of every roll and adjusts outcomes based on previous rolls. Time traveller will die of old age trying to scam this!

Usage

import { createCoin } from 'unfair-dice';
const coin = createCoin(); // or createDice(2)
console.log(coin.flip()); // 0 or 1

or using CommonJS:

const { createCoin } = require('unfair-dice');
const coin = createCoin(); // or createDice(2)
console.log(coin.flip()); // 0 or 1

or using array:

import { createDice } from 'unfair-dice';
const coin = createDice(['heads', 'tails']);
console.log(coin.flip()); // heads or tails

or create a d6:

import { createDice } from 'unfair-dice';
const d6 = createDice(6);
console.log(d6.roll()); // 0, 1, 2, 3, 4 or 5

State

import { createDice, createFromState } from 'unfair-dice';
const d6 = createDice(6);
d6.roll();
// ...
const saveState = d6.getState(); // save it somewhere as json, etc..
const d6Clone = createFromState(saveState); // recover it from state

or using CommonJS:

const { createDice, createFromState } = require('unfair-dice');
const d6 = createDice(6);
d6.roll();
// ...
const saveState = d6.getState(); // save it somewhere as json, etc..
const d6Clone = createFromState(saveState); // recover it from state

About

🎲 Dice that protects you from time travelers!

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors