View Full Version : All Possible Stat Blocks

2008-08-29, 01:22 AM
I'm brushing up on my programming and I've run amiss. This script should return all stat blocks for a 20 point buy with a cumulative bonus of +6 or more, and a maximum single stat value of 17, but only returns values up to 16 (cost[6]). What gives? It's a recursive script using FOR statements to produce permutations (at least, that's what I want it to do).

Any thoughts?


2008-08-29, 02:59 AM
You should learn Python or Perl or some other scripting language for small things like this; using C++ for something this small is unnecessarily complicated.

Anyway, look at what you did here:

for(f=0; f<=8; f++)
If you still don't see it: You're using 'f' twice. This means that 'f' gets overwritten with a cost (say, 9), then immediately used to index into bonus[], which has a size of 8... which, in turn, reads memory from goodness knows where, screwing up your results (and even when it isn't going out of bounds, you still get the wrong result.)

You did this in every single 'if' loop. I'm surprised you got any correct results at all... look at your results again, they ought to be all wrong.

2008-08-29, 03:30 AM
Yeah as what Aquilon. Your screwing up your loops by assigning the index variables a value from the bonus array, causing the program to lose count of how many iterations it's done in a loop.

Edit: this is probably the wrong forum for this kind of thing?