1. Parsing a Dice Roll String
- Posted by cklester <cklester at yahoo.com> Aug 04, 2004
- 453 views
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) I actually tried starting this function, but couldn't get through it. Anybody else want to try? :) The current roller and a die-roll graphing program can be found here: http://www.cklester.com/euphoria/ Thanks!!! -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/
2. Re: Parsing a Dice Roll String
- Posted by "Christian Cuvier" <Christian.CUVIER at agriculture.gouv.fr> Aug 05, 2004
- 453 views
> 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) > > I actually tried starting this function, but couldn't get through it. > Anybody else want to try? > > The current roller and a die-roll graphing program > can be found here: http://www.cklester.com/euphoria/ > > Thanks!!! > -=ck 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? <number> and <sides> are positive integers, <constant> is an atom.. <operation> is any of +-*/ (any more?) Did I get it? Regards CChris
3. Re: Parsing a Dice Roll String
- Posted by Matt Lewis <matthewwalkerlewis at yahoo.com> Aug 05, 2004
- 455 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) > > > > 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? > <number> and <sides> are positive integers, <constant> is an atom.. > <operation> is any of +-*/ (any more?) > Did I get it? It would sort of work. If you put these types of things through matheval, here's what you'd get: 3d6+5: { POLYNOMIAL, "D6", {5,3}} 4d6-lowest: { ADD, { VAR, "D6", 4 }, { VAR, "LOWEST", {-1} }} 2d10*3-3d4: { ADD, { VAR, "D10",{6}},{ VAR,"D4",{-3}}} One problem is that matheval tries to simplify things if it can, so 2d10*3 looks like 6d10 to it, even though that's not correct. Also, it tries hard to make things into polynomials if possible, since that's a lot more compact, and also faster to evaluate. If you took out the call_func( SIMPLIFY, {expr[1]}) call at the end of Parse() in parseval.e, you might be able to avoid some of these things. Matt Lewis
4. Re: Parsing a Dice Roll String
- Posted by cklester <cklester at yahoo.com> Aug 05, 2004
- 449 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/
5. Re: Parsing a Dice Roll String
- Posted by "Christian Cuvier" <Christian.CUVIER at agriculture.gouv.fr> Aug 05, 2004
- 457 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
6. Re: Parsing a Dice Roll String
- Posted by cklester <cklester at yahoo.com> Aug 05, 2004
- 459 views
Christian Cuvier wrote: > euphoric wrote: > > (<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)? That formula wouldn't perform what's inside the parens four times. Instead, it would create the number of faces using the formula inside the parens, then roll 4 dice with that number of faces. So, for instance, 2d(3d4) would roll two dice whose sides equalled from 3 up to 12. If you want to repeat a roll action, use something like 4:3d4 Which would now roll 3d4 four times and provide each result. In the simple version, we can ignore these types. In the advanced version, sure, why not? The only reason I can see for doing that would be statistical analysis. It wouldn't be very applicable. > 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"? Right, but remember that 4d9-2*Highest is not the same as 4d9-1stHighest-2ndHighest > Should we parse '6d6-H3" (remove third highest individual outcome)? > Then, wht about "6d6-3L" (remove the three lowest individual oitcomes)? Yeah, sure! (Again, maybe for the advanced version. ;) ) > 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 Well, get at it! And send me questions when ya got 'em. -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/
7. Re: Parsing a Dice Roll String
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Aug 05, 2004
- 440 views
On Wed, 04 Aug 2004 16:39:59 -0700, cklester <guest at RapidEuphoria.com> wrote: >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) > would say the strings "d(6,3)+5" "d(6,4)-Lowest" "d(6,4)+Highest" "d(10,2)*3-d(4,3)" "d(12,5)/10" be acceptable? If so, I think my expression evaluator would cope. Let me know & I'll try and knock up a quick demo. Regards, Pete
8. Re: Parsing a Dice Roll String
- Posted by cklester <cklester at yahoo.com> Aug 05, 2004
- 456 views
Pete Lomax wrote: > > > 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) > > > would say the strings > "d(6,3)+5" > "d(6,4)-Lowest" > "d(6,4)+Highest" > "d(10,2)*3-d(4,3)" > "d(12,5)/10" > be acceptable? All you'd have to do is take the expression and change any XdYs to d(X,Y). Sounds reasonable. -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/
9. Re: Parsing a Dice Roll String
- Posted by "Christian Cuvier" <Christian.CUVIER at agriculture.gouv.fr> Aug 06, 2004
- 457 views
>>This is the issue. >>> First off, are things like "4d(3d6-Highest)" allowed (perform 4 times the >>> roll >>> described inside the inner parentheses)? > > > That formula wouldn't perform what's inside the parens four times. > Instead, it would create the number of faces using the formula inside > the parens, then roll 4 dice with that number of faces. > > So, for instance, 2d(3d4) would roll two dice whose sides equalled > from 3 up to 12. > I see. And I will assume you don't need it... > If you want to repeat a roll action, use something like > > 4:3d4 > > Which would now roll 3d4 four times and provide each result. > > In the simple version, we can ignore these types. In the advanced > version, sure, why not? The only reason I can see for doing that > would be statistical analysis. It wouldn't be very applicable. > Not necessarily. Assume you want to simulate some help from Luck. Then you repeat a roll of any complexity, andtake the best outcome of the "possible futures". The : operator will be easy to implement. > >>> 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"? > > > Right, but remember that > > 4d9-2*Highest > > is not the same as > > 4d9-1stHighest-2ndHighest > > >>> Should we parse '6d6-H3" (remove third highest individual outcome)? >>> Then, wht about "6d6-3L" (remove the three lowest individual oitcomes)? > > > Yeah, sure! (Again, maybe for the advanced version. ) > Again, not a real issue. For instance, "8d6-2*3H2" will create a sequence of 8 rand(6), add this up, get the slice [8-1-(3-1)..8-1] from the above, add it up and double, to finally substract this from the first one. The real problem would be "(4+3*2)d6", and I'd rather leave this one for the advanced version. I don't care what you put inside parentheses as long as it's not nested parentheses, because here the headaches start. > >>> 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 > > > Well, get at it! And send me questions when ya got 'em. > I'll tell you. I didn't consider the issues involved with writing to list_Rolls, perhaps there's none. > -=ck CChris
10. Re: Parsing a Dice Roll String
- Posted by "Kat" <gertie at visionsix.com> Aug 06, 2004
- 468 views
Is it like this?: -GameServ- DESCRIPTION: -GameServ- The ROLL command simulates the throwing of a set of -GameServ- dice, fitting the given criteria. -GameServ- -GameServ- a is the number of separate outputs to give (optional) -GameServ- b is the number of dice to roll (but not output) (optional) -GameServ- c is the number of sides each dice has -GameServ- d is the modifier for each roll (optional) -GameServ- -GameServ- EXAMPLES: -GameServ- -GameServ- To roll 3 die, each with 6 sides, and return 2 results -GameServ- /GameServ roll 2#3d6 -GameServ- -GameServ- To roll 1 die, with 10 sides, and add 3 to each result -GameServ- /GameServ roll d10+3 -GameServ- -GameServ- To roll 2 die, with 3 sides, and take 1 from each result -GameServ- and send the results to #sorcery: -GameServ- /GameServ roll #sorcery #2d3-1 -GameServ- -GameServ- Note: dice rolls in channel are limited to ChanServ level -GameServ- MAOP(4) operators. Unless the GS_ROLL option is enabled, -GameServ- see /ChanServ help set gs_roll for more information. -GameServ- Kat