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