ChrisE
Joined: Apr 13, 2013
• Posts: 32
April 24th, 2013 at 10:30:50 AM permalink
This came out a bit hard to read. Here's the code on pastebin with syntax highlighting:
http://pastebin.com/UQ8w8KLQ
ChrisE
Joined: Apr 13, 2013
• Posts: 32
April 24th, 2013 at 10:58:08 AM permalink
New version with the next set of loops, things are looking a little crazy. I'm fairly certain I'm not doing this right!

http://pastebin.com/PAuz94gr

It says to add array2, subtract array1 where it overlaps, then add back in array0. Is this how you do that?

Array2:
`for (int j = 0; j < array2[0].Length; j++)            {                drawPayouts += array2[HandIndex3(drawArray[0], drawArray[1], drawArray[2])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[0], drawArray[1], drawArray[2], drawArray[3])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[0], drawArray[1], drawArray[2], drawArray[4])] * drawArray[5];                drawPayouts += array2[HandIndex3(drawArray[0], drawArray[1], drawArray[3])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[0], drawArray[1], drawArray[2], drawArray[3])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[0], drawArray[1], drawArray[4], drawArray[3])] * drawArray[5];                drawPayouts += array2[HandIndex3(drawArray[0], drawArray[1], drawArray[4])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[0], drawArray[1], drawArray[2], drawArray[4])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[0], drawArray[1], drawArray[4], drawArray[3])] * drawArray[5];                drawPayouts += array2[HandIndex3(drawArray[3], drawArray[1], drawArray[2])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[0], drawArray[1], drawArray[2], drawArray[3])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[4], drawArray[1], drawArray[2], drawArray[3])] * drawArray[5];                                drawPayouts += array2[HandIndex3(drawArray[4], drawArray[1], drawArray[2])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[0], drawArray[1], drawArray[2], drawArray[4])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[4], drawArray[1], drawArray[2], drawArray[3])] * drawArray[5];                                drawPayouts += array2[HandIndex3(drawArray[0], drawArray[3], drawArray[2])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[0], drawArray[1], drawArray[2], drawArray[3])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[0], drawArray[4], drawArray[2], drawArray[3])] * drawArray[5];                                drawPayouts += array2[HandIndex3(drawArray[0], drawArray[4], drawArray[2])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[0], drawArray[1], drawArray[2], drawArray[4])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[0], drawArray[4], drawArray[2], drawArray[3])] * drawArray[5];                                drawPayouts += array2[HandIndex3(drawArray[0], drawArray[3], drawArray[4])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[0], drawArray[4], drawArray[2], drawArray[3])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[0], drawArray[1], drawArray[4], drawArray[3])] * drawArray[5];                               drawPayouts += array2[HandIndex3(drawArray[3], drawArray[1], drawArray[4])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[4], drawArray[1], drawArray[2], drawArray[3])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[0], drawArray[1], drawArray[4], drawArray[3])] * drawArray[5];                                drawPayouts += array2[HandIndex3(drawArray[2], drawArray[3], drawArray[4])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[4], drawArray[1], drawArray[2], drawArray[3])] * drawArray[5];                drawPayouts -= array1[HandIndex4(drawArray[0], drawArray[4], drawArray[2], drawArray[3])] * drawArray[5];                                if (array0[HandIndex5(drawArray)] == j)                    { drawPayouts++; }            }`
JB
Joined: Oct 14, 2009
• Posts: 2089
April 24th, 2013 at 11:05:27 AM permalink
It's hard to say whether or not it's correct.

What you should do is treat each hold as a 5-binary-digit number ranging from 00000 to 11111 binary, with a 0 indicating that the card in that position is discarded and a 1 indicating that the card is held. Make sure the five card numbers are sorted from lowest to highest (or highest to lowest - whichever you prefer; I do lowest to highest). Then convert each 5-binary-digit number to decimal, 0 to 31, and use the bits in the binary representation of the number to determine which totals to add or subtract to compute the counts on the draw. See here for more info.
ChrisE
Joined: Apr 13, 2013
• Posts: 32
April 24th, 2013 at 11:47:29 AM permalink
Maybe I just need to take a while to think about it, but I'm not really understanding that. This project is starting to make me question myself!
JB
Joined: Oct 14, 2009
• Posts: 2089
April 24th, 2013 at 12:30:37 PM permalink
First, loop through every single hand (not just the simplified 134,459 hands). Score the hand and update the global totals for each n-card combination (from the hand) for the outcome the hand represents. For example, if the hand is 2♣ 3♠ 4♥ J♦ J♣, the outcome is Jacks or Better (outcome[1]), so you would increase the total number of Jacks or Better outcomes for each possible n-card combination for this hand.

Then use the global totals to calculate the number of outcomes on the draw for each of the 134,459 unique hands, according to the 32 formulas shown in the Sierpinski Triangle in the above link, and weighting the results appropriately to determine the totals for the game as a whole.
ChrisE
Joined: Apr 13, 2013
• Posts: 32
April 24th, 2013 at 12:49:50 PM permalink
Okay, I'll have to try that, because that craziness I was trying is up to 45 seconds run time!

Thank you.
JB
Joined: Oct 14, 2009
• Posts: 2089
April 24th, 2013 at 2:43:02 PM permalink
Quote: ChrisE

Okay, I'll have to try that, because that craziness I was trying is up to 45 seconds run time!

Thank you.

Don't expect lightning-fast analysis without making even more optimizations. The code in the video poker calculator has several layers of optimizations which make the code very ugly for humans to read and understand, but extremely fast for computers to execute, since execution speed was a higher priority than code readability. I wouldn't be able to explain the end result without explaining all of the optimizations made along the way. I might put together a more detailed explanation of it sometime in the near future.
ChrisE
Joined: Apr 13, 2013
• Posts: 32
April 24th, 2013 at 10:31:49 PM permalink
Well, when all was said and done the run time is ~1 minute, which isn't terrible but it's far from good. That doesn't matter much because clearly something I'm doing is wrong, because it says full pay JoB has a 0.6786964 return! Something is clearly very wrong. ;) Thanks for the help so far... I'll let you know if I get it working.
CrystalMath
Joined: May 10, 2011
• Posts: 1826
April 25th, 2013 at 6:33:57 AM permalink
Quote: ChrisE

Well, when all was said and done the run time is ~1 minute, which isn't terrible but it's far from good. That doesn't matter much because clearly something I'm doing is wrong, because it says full pay JoB has a 0.6786964 return! Something is clearly very wrong. ;) Thanks for the help so far... I'll let you know if I get it working.

I run under a minute without simplifying the deck, so I know you can do far better. Other than that, my method is nearly identical to JBs.
I heart Crystal Math.
ChrisE
Joined: Apr 13, 2013
• Posts: 32
April 26th, 2013 at 6:05:25 PM permalink
I think I've found where the error may be coming from, but I'm not sure why.

`        Debug.Log(array1[HandIndex4(0, 1, 2, 3)][STRAIGHT]);        Debug.Log(array1[HandIndex4(0, 2, 3, 1)][STRAIGHT]);        Debug.Log(array1[HandIndex4(0, 1, 3, 2)][STRAIGHT]);`

So that's looking in array1 for how many straights there are. It should be the same for each because they are all suited 2, 3, 4, 5 just listed in a different order. Sadly, they're giving me the index numbers: 0, 20821, and 47 with the results of the debugs being:

`608`

This makes zero sense to me, and I have no clue what's going on at this point. Any ideas?