Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rely on tables to implement repetitions and improve use of math operations #1

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

caewok
Copy link

@caewok caewok commented Jul 10, 2020

This is a relatively substantial rethinking of how to handle rolling in order to accommodate repetitions. The structure is as follows:

  • Dice set. Any given dice set, such as 4d6, 20, 4d6!>5, or 4d6>5, can be split into three parts: the base roll (e.g., 4d6), modifications (keep high, keep low, explode, etc.), and success test.
  • Matching patterns. The list of patterns are basically the same, with minor modifications. A list is used to track modification patterns and how to calculate each modification, and a separate list is used to track successes.
  • Rolltable class. A data frame is the base for this class. Each row represents a repetition for a specific dice set (where a dice set is something like 4d6 or 20 or 4d6!>5. The columns contain outputs from pattern matching to identify base roll, modification, and success, and also store relevant dice rolls. So for a given row, Base Roll would store the rolls for a dice set, such as for 4d6: 4,3,6,1, relying on the feature of data frames to store vectors as a list column. Calculated Roll is the total set of rolls with modifications applied (such as explode). A group of success columns track successes where applicable. Example: print(rolltable("4d6!>6>=5", repetitions = 3), rolls = TRUE)
  • Rolltable_calculated class. The "by" function return is the base for this class. By calculating a rolltable, you can get the result, but you can also get summaries such as median, mean, etc., calculated over the repetitions. Example: calculate(rolltable("4d6", repetitions = 100))
  • Virtual rollr class. Links rolltable and rolltable_calculated so that mathematical operations work.
  • Math operations. Implemented Ops methods for rolltable and rolltable_calculated. So one can apply an arbitrary set of mathematical operations and get back a rolltable_calculated. Operations are applied per repetition. Example:rolltable("4d6", repetitions = 5) + rolltable("20") returns a rolltable_calculated class representing five repetitions of "4d6 + 20."

The roll_dice function is modified to account for additional Ops, so that a user can enter an arbitrary formula such as roll_dice("(4d6! + 20) * 3 - 1d4"). A user can also do direct logical comparisons: roll_dice("2d20h1 > 10", repetitions = 100) or roll_dice("2d20h1 > 2d20l1", repetitions = 100).

Works with existing dice sets, and adds ability to handle:

  • 1d10!>9 - Explode nine and ten.
  • 3d10!>=8 - nWoD roll: tens explode, eights and up are treated like a success.
  • 4dF - Fudge/Fate dice.
  • 1d10t10 - If a ten is rolled then count it twice.
  • repeat (4d6k3, 6) - Roll D&D 5e ability score six times (to generate a new character). You can run print(rolltable("4d6h3", repetitions = 6), rolls = TRUE). Probably could use a user-friendly interface.

caewok added 10 commits July 8, 2020 15:59
…ns. Use a list of tables, one for each dice set, to store rolls and related information. Can be broken down into three parts:

1. Initial rolls. e.g., 3d6.
2. Modifications. e.g. exploding or keep highest.
3. Successes.

Use an S3 class for the list of tables structure, storing other relevant information, like the command, in attributes. R6 might be better for this (particularly for the re-rolling of tables), but then we have to deal with the fact that R6 modifies in place, which is a bit counterintuitive for general R users.

Successes could be pulled out as a method, but that would break the use of command as the primary way to set up the dice rolling parameters.
…e. Instead of storing a list, store a simple dataframe and use class methods to implement addition, subtraction, etc. The class dataframe will store all replications.

Changed rolltable class and methods accordingly.
…nitely long mathematical operations using anything from the Ops set of functions.

Added documentation for roll_dice and rolltable.
…on where 1d6+1 results in tbls[[tbls[[2]]]]+1 instead of tbs[[1]]+tbls[[2]]
Adjust tests to account for changes in underlying functions regarding rolltables. Fix minor errors and simplify how matches for roll patterns are stored.
…tion of parameters; conform inherited methods.
@Felixmil
Copy link
Owner

Felixmil commented Jul 10, 2020

😲😲😲 I did not expect any collaboration efforts on this !

I’m glad you were interested enough by the idea behind RollR to dig through my nooby code. I hope it wasn’t too much a pain to work with.

Thank you for investing time in this. I will try your version and review your PR soon. It looks promising !

@Felixmil
Copy link
Owner

Felixmil commented Nov 13, 2020

I finally got time to dive into your PR.

It is indeed substantial ! I read almost all the code but I have troubles understanding some parts, especially since I never worked with classes in R. However the consistent documentation you wrote is helping me a lot.

Anyway, I played around with it and I'm very happy to see that it works very well and in so many different ways, it is much powerful and got more potential than before. So thank you !

I just have concerns about user experience, ease of use, clarity of console feedback and tests but I think I will be able to work on it on my own once I understand correctly all your PR.

Once again, thank you, I am learning a lot from your code. 💯

Ongoing Process:

  • Read PR
  • Checkout on new branch
  • Pass all tests
  • Read new code and documentation
  • Understand all modifications to code
  • Questions to author
  • Suggest/Do modifications
  • Merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants