MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: D&D Dice

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37482] Re: [mg37457] D&D Dice
  • From: Kyriakos Chourdakis <tuxedomoon at yahoo.com>
  • Date: Fri, 1 Nov 2002 01:43:00 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

One can define the function "d0" for dice, that
creates the table of xd0y rolls, in a different form
than yours:

In: 
d0[x_Integer, y_Integer] :=
  Module[{A},
    A = Table[i, {i, y}];
    Nest[Flatten[Outer[Plus, #1, A]] &, A, x - 1]
    ]

This can be called infix, therefore one would get

In: 
3~d0~4
Out: 
{3, 4, 5, 6, 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 4, 5,
6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10, 5, 6, 7, 8,
6, 7, 8, 9, 7, 8, 9, 10, 8, 9, 10, 11, 6, 7, 8, 9, 7,
8, 9, 10, 8, 9, 10, 11, 9, 10, 11, 12}

Afterwards we can define the function "d" that counts
the results in the following way:

In:
d[x_Integer, y_Integer] := Module[{A, AMx, AMn},
    A = x~d0~y;
    AMx = Max[A];
    AMn = Min[A];
    Table[{i, Count[A, z_ /; z == i]}, {i, AMn, AMx}]
    ]

For example,

In: 
3~d~4
Out: 
{{3, 1}, {4, 3}, {5, 6}, {6, 10}, {7, 15}, {8, 21},
{9, 25}, {10, 27}, {11, 27}, {12, 25}, {13, 21}, {14,
15}, {15, 10}, {16, 6}, {17, 3}, {18, 1}}

The results is {roll,number of occurences}

I suppose you would be interested in getting a bar
chart with the result. We can use the BarChart
function of the Graphics package to define the new
function "dB" for bar chart:

In:
<< Graphics`Graphics`
dB[x_Integer, y_Integer] := Module[{B},
    B = x~d~y // Transpose;
    BarChart[B[[2]], Ticks -> {Transpose[{Table[i, {i,
Length[B[[1]]]}], B[[1]]}], Automatic}];
    ]

Then, if you input
In: 3~dB~4
you would get a bar chart with the results of a 3d4
roll.

Hope it helps,

Kyriakos

_____+*"*+____+*"*+___+*"*+__+*"*+_

Kyriakos Chourdakis
Lecturer in Financial Economics

URL: http://www.qmw.ac.uk/~te9001
tel: (++44) (+20) 7882 5086
Dept of Economics
University of London, QM
London E1 4NS
U.K.

====================================================
Consider yer basic 3d6 stat roll: What are the
possibilities?
This gives a table of all 6^3 = 216 rolls:

Table[i + i2 + i3, {i, 6}, {i2, 6}, {i3, 6}] //
MatrixForm

My question is this: How shall I set up a formula to
list the count of each
total?
====================================================

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


  • Prev by Date: RE: The equivalent of FindRoot for an interpolating function
  • Next by Date: RE: Is Mathematica capable of doing this?
  • Previous by thread: Re: D&D Dice
  • Next by thread: RE: D&D Dice