Results 1 to 3 of 3

Thread: Contest 14 - DnD Dice Roller - 2kaud - updated

  1. #1

    Thread Starter
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    690

    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++17 Compiler: Microsoft VS2019 (16.8.2)

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,764

    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.

  3. #3

    Thread Starter
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    690

    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++17 Compiler: Microsoft VS2019 (16.8.2)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width