-
Oct 2nd, 2020, 12:48 PM
#1
Contest 14 - DnD Dice Roller - 2kaud - updated
This is my second entry as I've managed to code a complete expression parser so that eg 1D%+1D10 is valid and evaluated to a single number. I didn't know whether I could get this completed in the time before the deadline, but I've managed. If I had had more time (started when contest first announced - instead of a 1 day ago!) I could have got the code tidied up a bit - removed global variables, better error reporting etc. However I think it does work. It uses Recursive Descent Parser - first split into tokens, then convert infix to postfix (RDP) and then evaluate the postfix.
Using the operators ()*/+- together with integer numbers and the die format (NO spaces), any valid expression can be entered and evaluated. If expressions are separated by space(s) then these are considered separate expressions and evaluated separately.
eg
1d%+1d10
(2d10+%d)*3
(2d10*2+%d+2)/2
2d20 d10 (gives 2 results)
2d20+d10 (gives 1 result)
See the fiddle at https://repl.it/repls/ElementaryKlutzyNagware#main.cpp
If you can't accept this because I've already submitted one, fair enough. Try it anyhow.
All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
Oct 26th, 2020, 05:05 PM
#2
Re: Contest 14 - DnD Dice Roller - 2kaud - updated
The program worked without issues, however it was definitely over engineered due to ambiguity in the rules that I outlined.
-
Oct 27th, 2020, 10:01 AM
#3
Re: Contest 14 - DnD Dice Roller - 2kaud - updated
OK. The first entry I submitted was probably more in line with what you were expecting. I was working towards a full-featured dice roller as per the wiki spec - but didn't have time as I only started the day before the closing date, as originally C++ wasn't specified.
Congrats to wossy.
All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|