I just won the about.com monthly competition. I wrote a program to play the game Set. (A game I don't do very well against the women folk in the family). The program plays the game 10,000 times. It ran 5x faster than the next guy, and his was pretty fast.
I wrote it to use multiple threads so if you have more than one processor it will go REALLY REALLY fast.
The code ain't pretty but it is so screamingly fast it burnt a hole in my hard disk.
My favorite part is the shuffle, to make it fast I interleave (much like a real shuffle) the cards just one time.
// shuffle
register unsigned int i = 0;
register unsigned int j = 80;
do
{
if ((rbits & (1i64 << i)) != 0) // as we shuffle randomly swap cards
{
swapCards(deck[i],deck[j]); // interleave cards
--j;
}
} while (++i < 64);
Monday, May 5, 2008
Subscribe to:
Post Comments (Atom)
chris' shared items
Twitter Updates
Official blog of Chris Lee Runyan
Fastest C++ in the west.
No comments:
Post a Comment