Jump to content
  • Advertisement
Sign in to follow this  
Charles Jarret Grassi

Trying to write a basic D&D Character sheet program.

This topic is 2147 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, guys. This is my first post so I hope that this goes well, otherwise I will find myself in the corner of my faded-blue room sobbing profusely.

So I'm trying to write, with my limited knowledge of c and c++ (the latter I taught myself the basics in a few weeks over the summer), a somewhat-basic D&D Character sheet program.

The concept is somewhat skewed since my mind can't seem to wrap around what I want to achieve when rolling for ability scores and such. So far, I'm just striving for a simple program that can execute(Of course, without failing), take the input of the character's name, race, and possibly pick some storyline options, and then output them onto a .txt file on their desktop (which I'm trying to find a way to do through precise direction of the fopen deal), and such and such.

Sorry if this seems a bit mushy, I haven't slept much. Ha...

Anyway, what I'm trying to ask is;

How would one randomize four integers, being equal to that of a six sided dice, and then take the four numbers I get and remove the lowest integer, then add them together? I can't seem to wrap my brain around how I could pick out the lowest integer if something happens to come up the same, such as two fours, and two fives, how would i code it to remove just one of the fours, not both of them, so someone doesn't get the ability score of Ten?

If none of what I have just asked makes sense, I'm willing to answer any questions you might have.

And I know of the rule about no homework assignments on here, so to let you guys know this is strictly for pleasure. I'm trying to impress my RP Crew with this simple executable program that everyone can use to make five character sheets in five minutes instead of taking about 4 hours.

If someone can help me piece this together, I should be able to make an efficent program. :D Hopefully!

Share this post


Link to post
Share on other sites
Advertisement
You're basically wanting to just do a quick sort on the array and then either remove or ignore the initial element. C++11 has random number generation in the library with distribution, etc... but you could also use the C function rand() Edited by Saruman

Share this post


Link to post
Share on other sites
How would one do that quick sort? I was doodling on my white board trying to figure out the best possible way to sort out the random integers that would remove the lowest integer out of the four numbers without removing more than the one integer if it were to roll multiples of the same integer. I was messing around with trying to divide down the average of the rolls, but I always seemed to take out more or less than I needed out of the average. Such as if it were to randomize the integers 4, 3, 6, 2, I'd add them up into a variable, then divide it by the number of rolls and then remove that from the sum of the four. But that never worked. Could you explain what you mean by that quick sort?

Share this post


Link to post
Share on other sites
And to clarify, when you roll an ability score for a d20 based dungeons and dragons character sheet, you just roll four six-sided dice and remove the lowest number, then add up the total of the three remaining dice. if you happen to roll all sixes or a multiple of the lowest number, you would just take out one of the dice, or one of the multiples, and then add them up. That's what i'm trying to achieve in a simple function that I can print out onto the text file without having the players have to manually do it, which is time consuming. I said all this assuming you've never played D&D or any Tabletop rpg, but if you have then this is redundant. Haha.

Share this post


Link to post
Share on other sites
One way to implement Saruman's suggestion:

std::array<int, 4> rolls;
std::generate(rolls.begin(), rolls.end(), []() { return (rand() % 6) + 1; }); // fill the array with rolls
std::sort(rolls.begin(), rolls.end(), std::greater<int>()); // sort the array so biggest numbers are first
int total = std::accumulate(rolls.begin(), rolls.begin() + 3, 0); // add up the first three numbers

Share this post


Link to post
Share on other sites
Could you explain what those std::array and std::generate things are? I'm guessing those are class things? I'm not that far into c++ or c to quite understand what those mean, but I know about randomizing numbers and seeding and such. If it's not too much trouble, could you elaborate what's going on? :D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!