Monday, July 18, 2011

Fisher–Yates shuffle - Wikipedia, the free encyclopedia

Fisher–Yates shuffle - Wikipedia, the free encyclopedia

I've implemented something similar in my THC WP7 application for generating a 52 card deck. It goes something like this, and is probably something similar you'll find on the net,

1. Initialize a byte array and int array, the former for the selected cards and the latter the result.
2. Pick a number at random if it's not selected add it the card[i], mark initial[i] as true.
3. Continue until i == 52.

There are a few improvements I might make:

1. Instead of storing the byte array I can initialize the int array to a sentinel, i <= -1 || i > 52. This eliminates the 52*size(byte) values on the stack. However, it requires an O(n) amount of time to initialize the values, possible constant for all intents and purposes.
2. Improve the random distribution by using the Fisher-Yates (Knuth) variant. This means that the range of values selected decreases by one meaning that the Nth value is only ever selected once. This is an O(c) improvement as 1 number per iteration is not selected.

However, I'm going to try to performance test before I make any improvements to gauge the necessity, aside from improving the random distribution. Currently I have 8 threads each selecting a random number, not yet selected. Maybe by moving to the other algorithms I can eliminate the need for concurrency.

Wednesday, July 13, 2011

Texas Holdem Calculator Starting Hands Editor

I am currently developing a windows phone 7 app that allows users to view starting hands, currently from embedded sources.  However, I have also been working on a WPF application that allows them to be created/edited and exported.  This is almost complete.  I have a working prototype that allows starting hands to be created, edited and exported.  These are also able to be embedded in the THC app and loaded.  What remains is some code cleanup and re-factoring to improve the maintainability.

I have not yet published the app but plan to do so as soon as I can get one of the new WP7 phones that are due to release this fall.  I am open to suggestions on improvements or requests.

At this time, although the idea is to allow users to import their own starting hands into the app, I have not yet integrated HTTP or windows live access.  If MS decides to release a skydrive API for WP7 (aside from using live services via REST), I'll work on adding this functionality.  Stay tuned.

PS.  Both the THC and Starting Hands Generator will be open source via Sourceforge (check my profile for the link).