Menu
News
All News
Dungeons & Dragons
Level Up: Advanced 5th Edition
Pathfinder
Starfinder
Warhammer
2d20 System
Year Zero Engine
Industry News
Reviews
Dragon Reflections
White Dwarf Reflections
Columns
Weekly Digests
Weekly News Digest
Freebies, Sales & Bundles
RPG Print News
RPG Crowdfunding News
Game Content
ENterplanetary DimENsions
Mythological Figures
Opinion
Worlds of Design
Peregrine's Nest
RPG Evolution
Other Columns
From the Freelancing Frontline
Monster ENcyclopedia
WotC/TSR Alumni Look Back
4 Hours w/RSD (Ryan Dancey)
The Road to 3E (Jonathan Tweet)
Greenwood's Realms (Ed Greenwood)
Drawmij's TSR (Jim Ward)
Community
Forums & Topics
Forum List
Latest Posts
Forum list
*Dungeons & Dragons
Level Up: Advanced 5th Edition
D&D Older Editions
*TTRPGs General
*Pathfinder & Starfinder
EN Publishing
*Geek Talk & Media
Search forums
Chat/Discord
Resources
Wiki
Pages
Latest activity
Media
New media
New comments
Search media
Downloads
Latest reviews
Search resources
EN Publishing
Store
EN5ider
Adventures in ZEITGEIST
Awfully Cheerful Engine
What's OLD is NEW
Judge Dredd & The Worlds Of 2000AD
War of the Burning Sky
Level Up: Advanced 5E
Events & Releases
Upcoming Events
Private Events
Featured Events
Socials!
EN Publishing
Twitter
BlueSky
Facebook
Instagram
EN World
BlueSky
YouTube
Facebook
Twitter
Twitch
Podcast
Features
Top 5 RPGs Compiled Charts 2004-Present
Adventure Game Industry Market Research Summary (RPGs) V1.0
Ryan Dancey: Acquiring TSR
Q&A With Gary Gygax
D&D Rules FAQs
TSR, WotC, & Paizo: A Comparative History
D&D Pronunciation Guide
Million Dollar TTRPG Kickstarters
Tabletop RPG Podcast Hall of Fame
Eric Noah's Unofficial D&D 3rd Edition News
D&D in the Mainstream
D&D & RPG History
About Morrus
Log in
Register
What's new
Search
Search
Search titles only
By:
Forums & Topics
Forum List
Latest Posts
Forum list
*Dungeons & Dragons
Level Up: Advanced 5th Edition
D&D Older Editions
*TTRPGs General
*Pathfinder & Starfinder
EN Publishing
*Geek Talk & Media
Search forums
Chat/Discord
Menu
Log in
Register
Install the app
Install
Community
General Tabletop Discussion
*Geek Talk & Media
d20 die roll string parser and roller in C#
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="FormerlyDickensC" data-source="post: 4050010" data-attributes="member: 53954"><p>This is not a compiled app, just one class written in C#. </p><p></p><p>This is a static class 'Dice' using a static method 'Roll(string)' that accepts any normal type die roll string (including parenthetical groupings) and outputs the individual rolls, grouping break-downs, and totals as a string. I took this code from <a href="http://www.enworld.org/showthread.php?t=218682" target="_blank">HERE</a> , and hacked the java code into C#. </p><p></p><p>It works really well. Very versatile. It can take any number of dice, and any number of sides per dice, and any amount of modifiers. Spaces are not a problem for the string. Leave them in or out. </p><p></p><p>I love the use of parenthetical groupings. I think this is where it really shines. </p><p></p><p>EXAMPLE Input strings: </p><p>"(3d6+5)+10d12+(5d6+2)"</p><p>"10(10d100)"</p><p>"2d42+6d7-44"</p><p></p><p>EXAMPLE Output Strings: </p><p>"(5d6+15)+1d6 = 4+1+2+3+4+15+2 = 29+2 = 31"</p><p>"(5d6+15)+1d6 = 4+2+4+2+1+15+1 = 28+1 = 29"</p><p>"2d6+15 = 2+5+15 = 7+15 = 22"</p><p></p><p>This from the original coder: ...as you can see the parenthesis collect the different dice into separate groups in the next-to-last column, so for example:</p><p>(1+2+3)+4 = 1+2+3+4 = 6+4 = 10</p><p></p><p>To implement, call the Dice.Roll(string) method. There are actually two overloaded Roll methods. The second takes three int's and is used by the first. </p><p></p><p>The reason I made this was b/c I could find an infinite number of die rollers on the web, but no die roller that could accept complex roll strings AND was written in C# AND had the code available to look at. Hence the reason I post the code, and not a compiled app. There are enough of those. But I did find a java version here on these forums, and translated that and added some more code to it. Use it to make your own app. If you can't code, buy a book and learn how. I was an English major and I taught myself to code. .NET is a decent platform with good, free IDE's. Ideal for the hobbyist. </p><p></p><p>Check it out, take a look at the comments. Since I basically took all the code and cobbled pieces together, there might be ways to make it more efficient or elegant. But it can roll over a thousand rolls in a second, so whats the need to worry about it? I suggest you enter the string "1000(1000d100)" and see how long it takes. I guess that'd be like a million rolls, right?</p><p></p><p>Code is posted as is, use it at your own peril. I encourage reuse and modification of it, just include the original author's name etc etc. All the normal stuff. I'm not responsible for any of your own stupid decisions.</p><p></p><p>This is the first, and probably last thing I will ever contribute. But, hey...at least its something!</p><p></p><p>Bitches!</p><p></p><p></p><p>P.S. If you find any bugs, let me know here.</p></blockquote><p></p>
[QUOTE="FormerlyDickensC, post: 4050010, member: 53954"] This is not a compiled app, just one class written in C#. This is a static class 'Dice' using a static method 'Roll(string)' that accepts any normal type die roll string (including parenthetical groupings) and outputs the individual rolls, grouping break-downs, and totals as a string. I took this code from [URL=http://www.enworld.org/showthread.php?t=218682]HERE[/URL] , and hacked the java code into C#. It works really well. Very versatile. It can take any number of dice, and any number of sides per dice, and any amount of modifiers. Spaces are not a problem for the string. Leave them in or out. I love the use of parenthetical groupings. I think this is where it really shines. EXAMPLE Input strings: "(3d6+5)+10d12+(5d6+2)" "10(10d100)" "2d42+6d7-44" EXAMPLE Output Strings: "(5d6+15)+1d6 = 4+1+2+3+4+15+2 = 29+2 = 31" "(5d6+15)+1d6 = 4+2+4+2+1+15+1 = 28+1 = 29" "2d6+15 = 2+5+15 = 7+15 = 22" This from the original coder: ...as you can see the parenthesis collect the different dice into separate groups in the next-to-last column, so for example: (1+2+3)+4 = 1+2+3+4 = 6+4 = 10 To implement, call the Dice.Roll(string) method. There are actually two overloaded Roll methods. The second takes three int's and is used by the first. The reason I made this was b/c I could find an infinite number of die rollers on the web, but no die roller that could accept complex roll strings AND was written in C# AND had the code available to look at. Hence the reason I post the code, and not a compiled app. There are enough of those. But I did find a java version here on these forums, and translated that and added some more code to it. Use it to make your own app. If you can't code, buy a book and learn how. I was an English major and I taught myself to code. .NET is a decent platform with good, free IDE's. Ideal for the hobbyist. Check it out, take a look at the comments. Since I basically took all the code and cobbled pieces together, there might be ways to make it more efficient or elegant. But it can roll over a thousand rolls in a second, so whats the need to worry about it? I suggest you enter the string "1000(1000d100)" and see how long it takes. I guess that'd be like a million rolls, right? Code is posted as is, use it at your own peril. I encourage reuse and modification of it, just include the original author's name etc etc. All the normal stuff. I'm not responsible for any of your own stupid decisions. This is the first, and probably last thing I will ever contribute. But, hey...at least its something! Bitches! P.S. If you find any bugs, let me know here. [/QUOTE]
Insert quotes…
Verification
Post reply
Community
General Tabletop Discussion
*Geek Talk & Media
d20 die roll string parser and roller in C#
Top