Skip to content

Commit cab2e0a

Browse files
Improve python support and documentation
- make Card, Rank, Suit, CardSet hashab - clean up README.md - suppress warning from boost::math::binomial_coefficient - create some sets in the test script
1 parent 790907e commit cab2e0a

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

README.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
PokerStove
22
==========
33

4-
[![OpenHUB Metrics](https://www.openhub.net/p/pokerstove/widgets/project_thin_badge.gif)](https://www.openhub.net/p/pokerstove)
4+
Code available at: https://github.com/andrewprock/pokerstove
55

6-
PokerStove is a highly hand optimized C++ poker hand evaluation library. The Win32 Hold'em
7-
GUI was first released in 2002, and has been available as freeware since
8-
it's first release.
6+
PokerStove is a highly hand optimized C++ poker hand evaluation library.
97

10-
The core libraries of pokerstove are being open sourced. The project is
8+
The core libraries of pokerstove have been open sourced. The project is
119
currently in the process of reviewing and publishing the code. As code is
1210
reviewed and code sanitized further commits will be added.
1311

@@ -162,7 +160,7 @@ Once you have built the project with Python support there will be a
162160
python loader file and a shared object file. To test run the script
163161
from the build directory:
164162

165-
PYTHONPATH=python/pokerstove/ ../src/lib/python/test-python
163+
PYTHONPATH=build/python/pokerstove/ ./src/lib/python/test-python
166164

167165
For regular use you'll want to export the PYTHONPATH variable to your
168166
shell:
@@ -179,7 +177,8 @@ installable wheel for the pythong package. The commands below can be
179177
used to build/install/verify the package.
180178

181179
git clean -fxd && pipx run build
182-
python3 -m venv venv && . venv/bin/activate && pip install dist/pokerstove-*.whl
180+
python3 -m venv venv && . venv/bin/activate
181+
pip install dist/pokerstove-*.whl
183182
python src/lib/python/test-python
184183
deactivate
185184

src/lib/pokerstove/peval/Rank.h

+2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ class Rank
117117
* to these functions to friends.
118118
*/
119119
void encode(uint8_t c) { _rank = c%NUM_RANK; } // was encode
120+
public:
120121
uint8_t code() const { return _rank; }
122+
private:
121123
int rankBit() const { return 0x01 << _rank; }
122124

123125
static bool isRankChar(char c);

src/lib/pokerstove/util/combinations.test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ TEST(Combinations, time_boost)
2020
for (int i=0; i<6000; i++) {
2121
for (int k=0; k<10; k++) {
2222
for (int n=k; n<10; n++) {
23-
static_cast<size_t>(boost::math::binomial_coefficient<double>(n, k));
23+
(void)static_cast<size_t>(boost::math::binomial_coefficient<double>(n, k));
2424
}
2525
}
2626
}

src/lib/python/pokerstove.i

+21-6
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,46 @@
5555

5656
// support __repr__() with extension boilerplate
5757
%extend pokerstove::Rank {
58-
std::string __repr__()
59-
{
58+
std::string __repr__() {
6059
return $self->str();
6160
}
61+
62+
long __hash__() {
63+
return (long)$self->code();
64+
}
6265
}
6366

6467
%extend pokerstove::Suit {
65-
std::string __repr__()
66-
{
68+
std::string __repr__() {
6769
return $self->str();
6870
}
71+
72+
long __hash__() {
73+
return (long)$self->code();
74+
}
6975
}
7076

7177
%extend pokerstove::Card {
7278
std::string __repr__()
7379
{
7480
return $self->str();
7581
}
82+
83+
long __hash__() {
84+
return (long)$self->code();
85+
}
7686
}
7787

7888
%extend pokerstove::CardSet {
79-
std::string __repr__()
80-
{
89+
std::string __repr__() {
8190
return $self->str();
8291
}
92+
93+
// this will truncate if sizeof(long) < 8 bytes. This should be ok
94+
// as hashes are not expected to be unique for python.
95+
long __hash__() {
96+
return (long)$self->mask();
97+
}
8398
}
8499

85100
%extend pokerstove::PokerHand {

src/lib/python/test-python

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ r2 = Rank(4)
66
r3 = Rank('4')
77
print('-- rank --')
88
print(r1, r2, r3)
9+
s = {r1, r2, r3}
910

1011
s1 = Suit()
1112
s2 = Suit(2)
@@ -18,6 +19,8 @@ c2 = Card(2)
1819
c3 = Card('As')
1920
print('-- cards --')
2021
print(c1, c2, c3)
22+
s = {c1, c2, c3}
23+
l = [c1, c2, c3]
2124

2225
cs1 = CardSet()
2326
cs2 = CardSet(0x8E)
@@ -27,6 +30,7 @@ cs5 = CardSet('Ac8dKc')
2730
print('-- card sets --')
2831
print('empty card set: ', cs1)
2932
print(cs2, cs3, cs4)
33+
s = {cs1, cs2, cs3, cs4, cs5}
3034

3135
e1 = PokerEvaluation()
3236
e2 = PokerEvaluation(26214408)
@@ -97,5 +101,4 @@ print('holdem: ', pocket, flop)
97101
print('dealt (dead): ', dead)
98102
print('deck: ', d)
99103

100-
print('-- card distribution --')
101104

0 commit comments

Comments
 (0)