I'm a beginner at pyhton. i'm working on a poker game. currently i'm stuck at dealing every player two cards. dealing the flop, turn and river work fine but dealing the player cards doesn't work. I don't understand why it doesn't work. Any solutions, explanation, other approaches advice are appreciated. Link to my github with the full code Github
def deal(self, location, times=1):
for i in range(times):
location.cards.append(self.pop(0))
def deal_hole(self):
count = 0
while count < 2:
for player in self.players_not_out:
self.deck.deal(player, 1)
count += 1
The Deal_hole method should append two cards to all the player class instances at the attribute cards which is a list, but it returns a empty list. i used the following code to test the method
list_of_players = [player('a'), player('b'), player('c'), player('d')]
game = game('q')
deck = deck()
a = player('a')
b = player('b')
c = player('c')
d = player('d')
game.shuffle_deck()
game.deal_hole()
player.show_hand(a,a)
This returned: a's hand: []
In the code you use for testing, by doing the following:
a = player('a')you do not assign
player('a')fromlist_of_playersto variablea, but create another player with name"a". That is why you cannot see its cards. But it will work properly, when you do it like this:And speaking about good practices, you should not pass the player's name in the
show_hand()method, because it takesself.namefor printing, not thenameyou pass. So it's not used and its presence there is counterintuitive.Apart from that:
show_name()should return the string, not print it.class Player(object):, this means the same:class Player:. The inheritance is implicit.list_of_playerstoGame's__init__method, not intialize it outside and use that variable.CapCase,CamelCase), according to Python Style Guide....and some more.
You can get your code's review on Code Review Stack Exchange.