Feat: correction du Blackjack
This commit is contained in:
parent
7d301e7019
commit
b0e26e2c67
@ -243,9 +243,6 @@ def play_backjack(nbr_players):
|
||||
:param nbr_players: nombre de joueurs
|
||||
:return: la liste des joueurs gagnants
|
||||
|
||||
:example:
|
||||
>>>
|
||||
|
||||
"""
|
||||
winners = []
|
||||
deck = build_deck()
|
||||
@ -253,26 +250,23 @@ def play_backjack(nbr_players):
|
||||
dealer = Player("croupier")
|
||||
|
||||
# Première main
|
||||
dealer = draw(dealer, deck)
|
||||
dealer, deck = draw(dealer, deck)
|
||||
players, deck = first_draw(players, deck)
|
||||
still_in_game_players = File()
|
||||
while not players.is_empty():
|
||||
p = players.pop()
|
||||
print(p)
|
||||
if won(p):
|
||||
winners.append(p)
|
||||
elif can_play(p):
|
||||
still_in_game_players.append(p)
|
||||
else:
|
||||
print(f"{p} est éliminé")
|
||||
if winners:
|
||||
return winners
|
||||
|
||||
dealer = draw(dealer, deck)
|
||||
dealer, deck = draw(dealer, deck)
|
||||
if won(dealer):
|
||||
return [dealer]
|
||||
|
||||
players = still_in_game_players
|
||||
still_in_game_players = File()
|
||||
while not players.is_empty():
|
||||
p = players.pop()
|
||||
while p.want_continue(dealer.hand):
|
||||
@ -282,9 +276,29 @@ def play_backjack(nbr_players):
|
||||
break
|
||||
elif not can_play(p):
|
||||
break
|
||||
if can_play(p):
|
||||
pass
|
||||
if not can_play(p):
|
||||
break
|
||||
still_in_game_players.append(p)
|
||||
|
||||
if still_in_game_players.n == 0:
|
||||
return []
|
||||
|
||||
while dealer.want_continue(dealer.hand):
|
||||
dealer, deck = draw(dealer, deck)
|
||||
if won(p):
|
||||
return []
|
||||
elif not can_play(p):
|
||||
break
|
||||
|
||||
while not still_in_game_players.is_empty():
|
||||
p = still_in_game_players.pop()
|
||||
if not can_play(dealer):
|
||||
winners.append(p)
|
||||
elif p.score > dealer.score:
|
||||
winners.append(p)
|
||||
|
||||
return winners
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
play_backjack(3)
|
||||
print(play_backjack(3))
|
||||
|
Loading…
Reference in New Issue
Block a user