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

Started by
11 comments, last by Charles Jarret Grassi 11 years, 6 months ago
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!
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()
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?
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.
If you just want to get the sum, you could do something like:

int sum=0,min=7;
for(int i=0;i<4;i++)
{
int n=rand()%6+1;
if(n<min)min=n;
sum+=n;
}
sum-=min;

which will assign to sum the total of the 3 remaining dice after the lowest one is removed.
Dude. You're a genius. Thank you!
I always seem to over complicate things in my brain. -smh
You can use the standard library to have your program four to a text file that it creates, look it up, it's really easy.

I'm a game programmer and computer science ninja !

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here !

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
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

This topic is closed to new replies.

Advertisement