I completed the Yahtzee problem today, after a couple of days effort.
I first double checked my previous 2004 solution’s scoring function, there were a few gems in there that I had to reproove, like how the full house was worked out.
// a - e are the five dice rolls
int array[7] = { 0,0,0,0,0,0,0 };
array[a]++;
array[b]++;
array[c]++;
array[d]++;
array[e]++;
// full house
if ( ( array[a] + array[b] + array[c] + array[d] + array[e] ) == 13 )
{
scores[count][12] = 40;
}
I then rewrote the recursive function to remove my fancy std::list<int>
stuff and used simple arrays of ints, and wrote a completely naive checker. But at 6 billions checks per score set, it was never going to fit the time limit.
I then thought about it for a day, and this morning, wrote a version the skipped the skippable stuff, but it got the wrong answer, then I noticed a case I’d skipped that I shouldn’t have. I added that back in, and all of a sudden my code started giving really bad (low) score results.
I noticed the my best score function was entering (new_score > best_score)
when they were the same values.
Much muttering, explaining to my wife and children later…
I noticed a compiler warning:
warning C4390: ';' : empty controlled statement found; is this the intent?
from this:
if( new_value > best_value );
{
//cout << "b: " << best_value << " n: " << new_value << endl;
memcpy(best_set, current_set, sizeof(int)*13);
best_value = new_value;
}
after removing the stupid semicolon and debugging text, my solution solved the puzzle!