Game Development Reference
In-Depth Information
case SKEW_LEFT:
std::sort( vRolls.begin(), vRolls.end() );
iFirstDie = TotalToRoll - NumDie - 1;
iLastDie = TotalToRoll -1;
break;
case SKEW_RIGHT:
std::sort( vRolls.begin(), vRolls.end());
iFirstDie = 0 ;
iLastDie = NumDie - 1;
break;
default:
break;
} // end switch
for ( i = iFirstDie; i <= iLastDie; i++ ) {
TotalRoll += vRolls[i];
} // end for
return TotalRoll;
}
To handle any number of dice, we create a std::vector container. This will be
our temporary die-roll storage location. The number of dice that we are going to
roll is set by the number that we want to consider for our result ( NumDie ) plus the
number that we need to accomplish the skew ( SkewCount ).
After filling this vector with all the die roll results by calling our original
SingleDie() function, we sort the results. Depending on which way we are skew-
ing the curve, we then move the endpoints of the dice that we are going to consider.
For example, if the results of 4d6 rolls are [2, 3, 5, 6] and we are only going to be
dropping the lowest, we would only want to consider the second through fourth
positions in the array. (Note that the vectors are zero-based arrays, so we would be
Search WWH ::




Custom Search