Module:Dice: Difference between revisions

502 bytes removed ,  18:02, 11 July 2019
add comment with repository url
(Created page with "local Dice = {} Dice.__index = Dice --# Interface --[[ Get a dice distribution from a dice string, which is in the form of a list of terms separated by + and -. Each...")
 
(add comment with repository url)
Line 1: Line 1:
--[[
    Dice.lua
    The core repository for this Lua module can be found at:
    https://bitbucket.org/HeladoDeBrownie/dice/
--]]
local Dice = {}
local Dice = {}
Dice.__index = Dice
Dice.__index = Dice
Line 92: Line 99:


     return sum
     return sum
end
--# Main
-- If this module is run without arguments, run some sample cases.
if ... == nil then
    for i, diceString in ipairs{
        '1d6',
        '1d4',
        '1d3',
        '2d6',
        '2d3',
        '1d6+1',
        '1d6-1d4',
        '5d3+1d2-1',
        '1d10-1d7+8',
        '7-7-7',
        '0',
        '-1',
        '1d6-1d6',
    } do
        if i ~= 1 then
            print()
        end
        local dice = Dice.fromString(diceString)
        print('distribution:', diceString)
        print('minimum:', dice:minimum())
        print('mean:', dice:mean())
        print('maximum:', dice:maximum())
    end
end
end