Re: Parsing a Dice Roll String
- Posted by cklester <cklester at yahoo.com> Aug 05, 2004
- 448 views
Christian Cuvier wrote: > > Subject: Parsing a Dice Roll String > > posted by: cklester <cklester at yahoo.com> > > I'm writing a die roller and need to be > > able to parse a dice function string. > > Some examples: > > 3d6+5 (roll 6-sided die 3 times, add 5 to sum) > > 4d6-Lowest (roll 6-sided die 4 times, discard lowest die) > > 4d6-Highest (roll 6-sided die 4 times, discard highest die) > > 2d10*3-3d4 (roll 10-sided die twice, multiply by 3, then subtract > > the result of rolling a 4-sided die three times) > > 5d12/10 (roll 12-sided die five times, divide result by 10) > > > > The current roller and a die-roll graphing program > > can be found here: <a > > href="http://www.cklester.com/euphoria/">http://www.cklester.com/euphoria/</a> > > Well, I'd expect Matt's matheval.e to be able to handle this with minor text > translation. > My understanding of your pb is: parse a string like roll ::= > ({<number>d<sides>[<operation>(roll | <reference> | > <constant>])[<operation>])+ > > where <reference is any of "Lowest" or "Highest" (any more?). > What's to be stored in list_Rolls? The roll outcome? Yes, along with the dice forumla. 3 d6 17 3d6 etc... > <number> and <sides> are positive integers, <constant> is an atom.. > <operation> is any of +-*/ (any more?) > Did I get it? I think so! Now, where's the code for it, Parisian? :D I think simplified, it can be written like: (<number>d<sides>)+(<number>d<sides>|<constant>)... Where + is any operator and <constant> is "Highest," "Lowest," an actual number, or whatever other value I can come up with to modify the roll. -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/