Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add python implementation #6

Closed
HenryRLee opened this issue Oct 14, 2019 · 11 comments
Closed

Add python implementation #6

HenryRLee opened this issue Oct 14, 2019 · 11 comments

Comments

@HenryRLee
Copy link
Owner

Add python implementation, using the same algorithm, similar to the C++ implementation.

Create a directory named python and add python source code in it.

@HenryRLee
Copy link
Owner Author

I have some advice/guide that may help you with this implementation: You can start implementing a 5-card or a 7-card evaluator only, with unit tests, and make a PR for it. Then make consequential PRs for the rest of the evaluators.

It might not be easy to write test codes fully cover all the possible hands (enumerating all possibilities like the C++ implementation, which is using Cactus Kev's evaluator as a reference). To make it easier, you can just write test code only choosing a few examples in each rank category. For example, choose a few hands from Straight Flush, then a few from Four of a Kind, etc.

@ohwi
Copy link
Contributor

ohwi commented Oct 23, 2019

Hi. If you don't mind the fact that I'm new to coding, I think I can try this.

@HenryRLee
Copy link
Owner Author

Hi @ohwi, never mind. Try your best!

@ohwi
Copy link
Contributor

ohwi commented Oct 24, 2019

Hi @HenryRLee, before writing a code, I want to check my understanding. It would be very helpful if you could comment about my understanding.

  1. With the example given in the documentation, dp[4][4][5] = [0, 4000) can be split into [0, 1000), [1000, 2000), [2000, 3000), [3000, 4000).

  2. Each of the split are [0, 1000) with k=0, 1, 2, 3. With this observation, can infer that dp[l][i][j] = SUM{ dp[1][i][j-q] } for q in [0, 1, ..., l-1] and if j-q >= 0.

  3. By separating l-1, the equation becomes dp[l][i][j] = dp[l-1][i][j] + dp[1][i][j-l+1]. Here, dp[1][i][j-l+1] is 0 if j-l+1 is less than 0.

In documentation, recursion formula is dp[l][i][j] = dp[l-1][i][j] + dp[1][i][j-l], so I am little bit confused.

@HenryRLee
Copy link
Owner Author

HenryRLee commented Oct 24, 2019

Hi @ohwi, you're right. There is a mistake in the documentation. I'll fix it right away. Thank you for that.

In addition, you can refer to #2 for the workable code in generating the dp table.

@ohwi
Copy link
Contributor

ohwi commented Oct 25, 2019

Hi @HenryRLee, thank you for your comment and the information.

I'll refer #2 when I work with the dp table.

@ohwi
Copy link
Contributor

ohwi commented Oct 28, 2019

Hi @HenryRLee, I've done with 5 cards.
I ran unittest with cpp version of evaluate_5cards as a ground truth and passed.

However, since this is my first time to work using github with others, I want to check something before make a PR...

  1. Do I need to make consequential PRs after I finish the whole work? Or can I make PR only with 5 cards eval?
  2. I wrote some code to understand and test the tables like dp and noflush. Do I need to remove these before I make a PR?

Thank you.

@HenryRLee
Copy link
Owner Author

Hi @ohwi, you can make a PR once 5-card evaluator is ready, and the rest of the work can go into separate PRs in the future.

I would encourage you to include your table test codes to your PR, and I'll probably use them in C/C++ implementations if I find them useful.

@ohwi
Copy link
Contributor

ohwi commented Oct 30, 2019

Hi @HenryRLee, I'm working on 6 cards case, and I found that noflush6 is not containing 1620. My implementation and table copied from C++ are in same order, but the number is different.

Can you explain the way you iterated to build the table briefly?

@HenryRLee
Copy link
Owner Author

It's because 1620 (which is AAAK2) only exists in 5-card hands. Suppose one more card is introduced in this hand, it either gets a higher card than 2, or goes into a better category (full house or four of a kind).

The way I generated the flush and noflush tables are boring. I simply iterate all possible 6-card hands, find the best 5-card hand using Catus Kev's algorithm then get the correct value, run the hash function at the same time, and finally put the correct value to the corresponding slot in the hash table.

@ohwi
Copy link
Contributor

ohwi commented Oct 31, 2019

Thank you. I missed that the numbers are based on Cactus Kev's algorithm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants