#!/usr/bin/perl
#
# dize - quick and dirty table of dice probabilities
#
# Takes a single argument of a dice expression such as "2d6" or "3d4"
# or "2d10+(2d12/1d4)*1d8" and calculates the value/probability distribution
# then does a quick and dirty output of it to STDOUT.
#
# This and other hacks can be found at: http://oddgeek.info/
#
# Copyright (c) 2005 Jason A. Dour
#
# This software is provided 'as-is', without any express or implied warranty.
# In no event will the authors be held liable for any damages arising from the
# use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
#     1. The origin of this software must not be misrepresented; you must not
#     claim that you wrote the original software. If you use this software in a
#     product, an acknowledgment in the product documentation would be
#     appreciated but is not required.
#
#     2. Altered source versions must be plainly marked as such, and must not
#     be misrepresented as being the original software.
#
#     3. This notice may not be removed or altered from any source
#     distribution.
#

#
# Version Information
#
# 1.0	2005.08.04
#
# 	Quick and dirty example of how to use my Games::Dice::Probability module.
#

#
# Load the GDP module.
use Games::Dice::Probability;

# expr = dice expression to calc
$expr = shift;

# dobj = GDP object
$dobj = Games::Dice::Probability->new($expr);
$dist = $dobj->distribution();

#
# Format the output.
format STDOUT_TOP =
   VALUE     COMB/TOT.COMB (% CHANCE  )
.
format STDOUT =
@####### @#######/@<<<<<<< (@##.#####%)
$value, $$dist{$value}, $dobj->combinations(), $dobj->probability($value)*100
.

foreach $value ( sort {$a+0 <=> $b+0} keys( %$dist ) ) {
    write;
}

#
# We're done...go home.
exit(0);
