Re: Parsing a Dice Roll String
- Posted by "Christian Cuvier" <Christian.CUVIER at agriculture.gouv.fr> Aug 05, 2004
- 433 views
> > posted by: cklester <cklester at yahoo.com> > > 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. > This is the issue. First off, are things like "4d(3d6-Highest)" allowed (perform 4 times the roll described inside the inner parentheses)? Second, "would 4d6-Highest-Highest" be legal? If so, would it mean "4d9-2*Highest" or "4d6 and remove the two highest outcomes, adding up the rest"? Should we parse '6d6-H3" (remove third highest individual outcome)? Then, wht about "6d6-3L" (remove the three lowest individual oitcomes)? I may have other questions too... From Matt's reaction, and after a closer look at Kat's strtok, the latter is probably a better route to go. I may start coding this WE if I get all questions answered before Friday 17:00UTC. And, you know the kind of nasty questions that can arise when one starts coding :D CChris