in reply to Dice::Die

It seems like a lot of work to create an entirely new object for each execution of what is effectively int rand($dieType) + 1, especially with the length of the new() method. Why not allow a die object to be created once and then rolled as many times as desired?

One other point; the calculation of theoretical average should be: my $theoreticalAve = ($dieType + 1) / 2; which is (max + min) / 2. Consider a two-sided die (marked 1 and 2); the expected average is 1.5, rather than 1. :)

Replies are listed 'Best First'.
Re: Re: Dice::di
by ichimunki (Priest) on Jan 06, 2001 at 02:21 UTC
    This comment is altered

    I agree. Each type of die should be storable as an instance. For example, my $six_sider = Dice::Di->new( SIDES => 6 ). And useful methods would be
    my $roll = $six_sider->roll(); my @rolls = $six_sider->rolls(6); #note plural, although #with wantarr +ay() this can probably be folded into roll() my @char_trait_set = map {$six_sider->roll()} (1..3) # ?
      The point I was making is that, as the module is written, he can't make an object $six_sider and then call $six_sider->roll() as many times as he wants. The value for the roll is set in the new() method, and the module does not provide a method for generating a new roll on an already created object. Each die roll requires creating an entirely new object, calling its get_roll() method to find out what the die roll was, and then discarding the object.

      I agree with you that a roll() method, as you described, would be very useful.

Re: Re: Dice::di
by ryddler (Monk) on Jan 06, 2001 at 02:33 UTC
    Consider a two-sided die (marked 1 and 2)

    You mean a coin? ;-)
    I agree with chipmunk. I think you should create the object once, and then call a get_roll method from there.

    ryddler

      Consider a two-sided die (marked 1 and 2)

      You mean a coin? ;-)

      Yes, except I was trying to avoid ending up with (Heads + Tails) / 2. :)

Re: Re: Dice::di
by coreolyn (Parson) on Jan 06, 2001 at 02:17 UTC

    Update: The following post is an example of what happens when you don't read posts closely. I'd delete it, but somehow that doesn't seem right..


    While it might seem like overkill, when you start assembling RPG Apps and need to hold and compare 5-12 dice rolls against 3-4 different charts (arrays) a dice object becomes kinda handy. This is just the very base to be inherited into a more robust Dice::Dice object. Besides, it's simplicity makes for easier understanding of the basic construction which was actually the real objective :)

    Thanks for the fix on the run script

    coreolyn