开发者

Algorithm to Check All Permutations of Slot Machine For Win

I have a program that has a slot machine with 5 columns and 5 images in each. I'm trying to find an efficient algorithm that can check all the permutations for several combinations that would indicate a win. Those combinations are: 2 pair of matching images, 3 of the same image, 4 of the same image, 5 of the same image, and finally 3 of the same image and 2 of the same image different from the first 3. I'm not concerned with order. Thanks for any tips or suggest开发者_C百科ions.


Use a dictionary / hashmap:

counts = {}
foreach image in row:
     // TODO: If the image is not already in the dictionary, add it.
    counts[image] += 1

Then you can check how many of each image you have by iterating over the values in the dictionary.


You could also have some sort of Dictionary or Hashtable datastructure (key/value pairs) with 5 elements. As you enumerate each column, add +1 to the value (the image, or as Mark Byers says, something that "uniquely identifies them," will be the key). Then sort your key/value datastructure. You can then create an FSM with your logic above to classify the winnings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜