Skip to content

Commit d27e033

Browse files
committed
debugged round privateIn
1 parent 487a7f2 commit d27e033

5 files changed

Lines changed: 55 additions & 53 deletions

File tree

pokerlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
'PlayerGroup',
2121
'Round',
2222
'Table'
23-
] + enums.__all__
23+
]

pokerlib/_handparser.py

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ class HandParser:
55
__slots__ = [
66
"original", "ncards", "cards",
77
"handenum", "handbase", "kickers",
8-
"__valnums", "__suitnums",
9-
"__flushsuit", "__straightindexes"
8+
"_valnums", "_suitnums",
9+
"_flushsuit", "_straightindexes"
1010
]
1111

1212
def __init__(self, cards: list):
@@ -18,20 +18,20 @@ def __init__(self, cards: list):
1818
self.handbase = []
1919
self.kickers = []
2020

21-
self.__valnums = [0] * 13
22-
self.__suitnums = [0] * 4
21+
self._valnums = [0] * 13
22+
self._suitnums = [0] * 4
2323
for value, suit in cards:
24-
self.__valnums[value] += 1
25-
self.__suitnums[suit] += 1
24+
self._valnums[value] += 1
25+
self._suitnums[suit] += 1
2626

27-
self.__flushsuit = None
27+
self._flushsuit = None
2828
for suit in Suit:
29-
if self.__suitnums[suit] >= 5:
30-
self.__flushsuit = suit
29+
if self._suitnums[suit] >= 5:
30+
self._flushsuit = suit
3131
break
3232

33-
self.__straightindexes = \
34-
self.getStraightIndexes(self.__valnums)
33+
self._straightindexes = \
34+
self._getStraightIndexes(self._valnums)
3535

3636
@property
3737
def handbasecards(self):
@@ -81,7 +81,11 @@ def __lt__(self, other):
8181
if s_val != o_val: return s_val < o_val
8282
return False
8383

84-
def addCards(self, cards):
84+
def __iadd__(self, cards):
85+
self._addCards(cards)
86+
return self
87+
88+
def _addCards(self, cards):
8589
self.original.extend(cards)
8690
self.ncards += len(cards)
8791
for card in cards: insort(self.cards, card)
@@ -91,19 +95,19 @@ def addCards(self, cards):
9195
self.kickers.clear()
9296

9397
for value, suit in cards:
94-
self.__valnums[value] += 1
95-
self.__suitnums[suit] += 1
98+
self._valnums[value] += 1
99+
self._suitnums[suit] += 1
96100

97101
for suit in Suit:
98-
if self.__suitnums[suit] >= 5:
99-
self.__flushsuit = suit
102+
if self._suitnums[suit] >= 5:
103+
self._flushsuit = suit
100104
break
101105

102-
self.__straightindexes = \
103-
self.getStraightIndexes(self.__valnums)
106+
self._straightindexes = \
107+
self._getStraightIndexes(self._valnums)
104108

105109
@staticmethod
106-
def getStraightIndexes(valnums):
110+
def _getStraightIndexes(valnums):
107111
straightindexes = [None] * 5
108112
straightlen, indexptr = 1, sum(valnums)
109113
for i in reversed(range(len(valnums))):
@@ -123,12 +127,12 @@ def _setStraightFlush(self):
123127
counter = 0
124128
suited_vals, permut = [0] * 13, [0] * len(self.cards)
125129
for i, (val, suit) in enumerate(self.cards):
126-
if suit == self.__flushsuit:
130+
if suit == self._flushsuit:
127131
suited_vals[val] += 1
128132
permut[counter] = i
129133
counter += 1
130134

131-
suited_handbase = self.getStraightIndexes(suited_vals)
135+
suited_handbase = self._getStraightIndexes(suited_vals)
132136
if suited_handbase is not None:
133137
self.handenum = Hand.STRAIGHTFLUSH
134138
self.handbase = [permut[i] for i in suited_handbase]
@@ -140,7 +144,7 @@ def _setFourOfAKind(self):
140144
self.handenum = Hand.FOUROFAKIND
141145

142146
hindex = -1
143-
for valnum in self.__valnums:
147+
for valnum in self._valnums:
144148
hindex += valnum
145149
if valnum == 4: break
146150

@@ -151,7 +155,7 @@ def _setFullHouse(self):
151155

152156
threes, twos = [], []
153157
hindex = -1
154-
for val, valnum in enumerate(self.__valnums):
158+
for val, valnum in enumerate(self._valnums):
155159
hindex += valnum
156160
if valnum == 3: threes.append((val, hindex))
157161
elif valnum == 2: twos.append((val, hindex))
@@ -165,22 +169,22 @@ def _setFlush(self):
165169

166170
counter = 0
167171
for i in reversed(range(self.ncards)):
168-
if self.cards[i][1] == self.__flushsuit:
172+
if self.cards[i][1] == self._flushsuit:
169173
self.handbase.append(i)
170174
counter += 1
171175
if counter == 5:
172176
break
173177

174178
def _setStraight(self):
175179
self.handenum = Hand.STRAIGHT
176-
self.handbase = self.__straightindexes
180+
self.handbase = self._straightindexes
177181

178182
def _setThreeOfAKind(self):
179183
self.handenum = Hand.THREEOFAKIND
180184
self.handbase.clear()
181185

182186
hindex = -1
183-
for valnum in self.__valnums:
187+
for valnum in self._valnums:
184188
hindex += valnum
185189
if valnum == 3: break
186190

@@ -191,7 +195,7 @@ def _setTwoPair(self):
191195
self.handbase.clear()
192196

193197
hindex, paircounter = self.ncards, 0
194-
for valnum in reversed(self.__valnums):
198+
for valnum in reversed(self._valnums):
195199
hindex -= valnum
196200
if valnum == 2:
197201
self.handbase.extend([hindex+1, hindex])
@@ -202,7 +206,7 @@ def _setOnePair(self):
202206
self.handenum = Hand.ONEPAIR
203207

204208
hindex = -1
205-
for valnum in self.__valnums:
209+
for valnum in self._valnums:
206210
hindex += valnum
207211
if valnum == 2: break
208212

@@ -214,18 +218,18 @@ def _setHighCard(self):
214218

215219
def _setHand(self):
216220
pairnums = [0] * 5
217-
for num in self.__valnums: pairnums[num] += 1
221+
for num in self._valnums: pairnums[num] += 1
218222

219-
if None not in [self.__straightindexes, self.__flushsuit] \
223+
if None not in [self._straightindexes, self._flushsuit] \
220224
and self._setStraightFlush():
221225
pass
222226
elif pairnums[4]:
223227
self._setFourOfAKind()
224228
elif pairnums[3] == 2 or pairnums[3] == 1 and pairnums[2] >= 1:
225229
self._setFullHouse()
226-
elif self.__flushsuit is not None:
230+
elif self._flushsuit is not None:
227231
self._setFlush()
228-
elif self.__straightindexes is not None:
232+
elif self._straightindexes is not None:
229233
self._setStraight()
230234
elif pairnums[3]:
231235
self._setThreeOfAKind()

pokerlib/_round.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# should be kept within one object. #
1414
# That object has a generator-like property, #
1515
# so that, when sent valid input, #
16-
# it updates properties so it's ready #
17-
# for the next valid input. #
16+
# it updates properties which make it #
17+
# ready for the next valid input. #
1818
# #
1919
##################################################
2020

@@ -126,7 +126,7 @@ def _turnGenerator(self):
126126

127127
for player in self.players:
128128
player.played_turn = False
129-
player.hand.addCards(new_cards)
129+
player.hand += new_cards
130130
player.hand.parse()
131131

132132
self.table.extend(new_cards)
@@ -343,12 +343,11 @@ def close(self):
343343
self.finished = True
344344
self.publicOut(PublicOutId.ROUNDFINISHED)
345345

346-
347-
def privateIn(self, user_id, **kwargs):
346+
def privateIn(self, action, raise_by=0):
348347
"""Processes ivalidated user input"""
349348
# this is a standard action validation,
350349
# which can be overriden
351-
350+
print('private')
352351
player = self.current_player
353352
to_call = self.turn_stake - player.turn_stake[self.turn]
354353

pokerlib/_table.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from operator import add
22
from math import inf
33

4-
from .enums import *
4+
from .enums import PlayerAction
55
from ._player import Player, PlayerGroup
66
from ._round import Round
77

@@ -16,8 +16,8 @@ def __init__(self, _id, players, small_blind, big_blind):
1616
self.button = 0
1717
self.round = None
1818
self.interrupt = False
19-
self.__player_removal_schedule = []
20-
self.__player_addition_schedule = []
19+
self._player_removal_schedule = []
20+
self._player_addition_schedule = []
2121

2222
def __bool__(self):
2323
return 2 <= len(self.players.getNotBrokePlayers()) <= 9
@@ -29,17 +29,17 @@ def __eq__(self, other):
2929
return self.id == other.id
3030

3131
def __iadd__(self, players):
32-
self.__player_addition_schedule.extend(players)
32+
self._player_addition_schedule.extend(players)
3333
if not self.round: self._updatePlayers()
3434
return self
3535

3636
def __isub__(self, players):
37-
self.__player_removal_schedule.extend(players)
37+
self._player_removal_schedule.extend(players)
3838
if not self.round: self._updatePlayers()
3939
else:
4040
for player in players:
4141
if player.id == self.round.current_player.id:
42-
self.round.processAction(PlayerAction.FOLD)
42+
self.round.privateIn(PlayerAction.FOLD)
4343
elif player.id in self.round:
4444
player.is_folded = True
4545
return self
@@ -48,15 +48,15 @@ def __isub__(self, players):
4848
def all_players(self):
4949
return add(
5050
self.players,
51-
self.__player_addition_schedule
51+
self._player_addition_schedule
5252
)
5353

5454
# called only when round is finished
5555
def _updatePlayers(self):
56-
self.players.extend(self.__player_addition_schedule)
57-
self.players.remove(self.__player_removal_schedule)
58-
self.__player_addition_schedule.clear()
59-
self.__player_removal_schedule.clear()
56+
self.players.extend(self._player_addition_schedule)
57+
self.players.remove(self._player_removal_schedule)
58+
self._player_addition_schedule.clear()
59+
self._player_removal_schedule.clear()
6060

6161
def newRound(self, round_id):
6262
assert not self.round

tests/round_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from sys import path
2-
from pathlib import Path
1+
from os import chdir
32
from argparse import ArgumentParser
43

5-
path.append(str(Path().cwd().parent))
4+
chdir('..')
65

76
from pokerlib.enums import *
87
from pokerlib import HandParser

0 commit comments

Comments
 (0)