I wish to evaluate several different potential rules/scoring systems for a game. The game involves rolling three dice up to three times. In order to consider the results of each eventuality, I'm iterating over all the possible values of each of the nine possible rolls of the dice.
My question is whether the following brute force style coding is the best approach.
// get the result for each possible game
void Evaluate( const ScoringSystem& sys )
{
for( int d1=0; d1<6; ++d1 )
{
for( int d2=0; d2<6; ++d2 )
{
for( int d3=0; d3<6; ++d3 )
{
for( int d4=0; d4<6; ++d4 )
{
for( int d5=0; d5<6; ++d5 )
{
for( int d6=0; d6<6; ++d6 )
{
for( int d7=0; d7<6; ++d7 )
{
for( int d8=0; d8<6; ++d8 )
{
for( int d9=0; d9<6; ++d9 )
{
int rolls[] = { d1, d2, d3, d4, d5, d6, d7, d8, d9 };
// get the result for this particular game
sys.GetGameResult( rolls );
}
}
}
}
}
}
}
}
}
}
The code functions but is ugly and not extensible to a game with more dice. I've got an environment that supports C++17, so I'm open to newer ideas — as long as they don't make the code look too terrible.
(Tangent: 6^9 is over 10 million. I might be better off using pseudo-random numbers and just 'rolling' nine dice a million times. But I still want to know if there's a clever way to work through the permutations.)