Merge branch 'master' of https://git.wmi.amu.edu.pl/s444383/blackjack-fuzzy
This commit is contained in:
commit
43346d0c50
27
cards.py
27
cards.py
@ -1,4 +1,3 @@
|
||||
# import itertools
|
||||
import random
|
||||
from FuzzyControlSystem import getStartDecision, getSplitDecision, getHardHandDecision, getSoftHandDecision
|
||||
|
||||
@ -18,7 +17,6 @@ def shoe(n_of_decks: int = 1) -> list:
|
||||
for _ in range(n_of_decks):
|
||||
for _ in suits:
|
||||
deck.extend(vals)
|
||||
# deck.extend(itertools.product(vals, suits))
|
||||
|
||||
random.shuffle(deck)
|
||||
return deck
|
||||
@ -101,6 +99,20 @@ def has_blackjack_occured(hand: list):
|
||||
return True
|
||||
return False
|
||||
|
||||
def show_game_state(player_hand: list, dealer_hand: list, decision: str='') -> None:
|
||||
"""Print dealer and player card values and player decision
|
||||
|
||||
Args:
|
||||
player_hand (list): List of cards in player hand
|
||||
dealer_hand (list): List of cards in dealer hand
|
||||
decision (str, optional): Player decision. Will not be printed if defaults to ''.
|
||||
"""
|
||||
if decision and cards_eval(player_hand)[0] > 21:
|
||||
print(f"dealer: {cards_eval(dealer_hand)} player: {cards_eval(player_hand)} fail")
|
||||
elif decision:
|
||||
print(f"dealer: {cards_eval(dealer_hand)} player: {cards_eval(player_hand)} decision: {decision}")
|
||||
elif not cards_eval(player_hand)[0] > 21:
|
||||
print(f"dealer: {cards_eval(dealer_hand)} player: {cards_eval(player_hand)}")
|
||||
|
||||
def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list=[], bet: int=10) -> str:
|
||||
"""Single blackjack round
|
||||
@ -121,11 +133,7 @@ def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list =[], bet: int
|
||||
decision = ''
|
||||
while decision != 'stand' or decision != 'surrender':
|
||||
decision = AI(player_hand, face_up)
|
||||
if cards_eval(player_hand)[0] > 21:
|
||||
print(f"dealer: {cards_eval(dealer_hand)} player: {cards_eval(player_hand)} fail")
|
||||
else:
|
||||
print(f"dealer: {cards_eval(dealer_hand)} player: {cards_eval(player_hand)} decision: {decision}")
|
||||
|
||||
show_game_state(player_hand, dealer_hand, decision)
|
||||
if decision == 'hit':
|
||||
player_hand.append(next(shoe))
|
||||
elif decision == 'double down':
|
||||
@ -149,11 +157,8 @@ def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list =[], bet: int
|
||||
#dealer turn
|
||||
dealer_value = dealer(dealer_hand, shoe)
|
||||
player_value = max(cards_eval(player_hand))
|
||||
# print(dealer_value, player_value) #debug
|
||||
|
||||
|
||||
if not cards_eval(player_hand)[0] > 21:
|
||||
print(f"dealer: {cards_eval(dealer_hand)} player: {cards_eval(player_hand)}")
|
||||
show_game_state(player_hand, dealer_hand)
|
||||
|
||||
if player_value == 21 and has_blackjack_occured(player_hand):
|
||||
return 'player blackjack', bet
|
||||
|
Loading…
Reference in New Issue
Block a user