diff --git a/FuzzyControlSystem.py b/FuzzyControlSystem.py index 97f5557..6aef14a 100644 --- a/FuzzyControlSystem.py +++ b/FuzzyControlSystem.py @@ -251,11 +251,11 @@ def getSoftHandDecision(dealerCard, playerCardsVal, countedCardsVal, playerCards TriangleFuzzySet(6,11,11, term="high")], universe_of_discourse=[0, 11])) - FS.add_linguistic_variable("playerCardValue", LinguisticVariable([ - TriangleFuzzySet(0,0,5, term="low"), - TriangleFuzzySet(4,6,8, term="average"), - TriangleFuzzySet(7,9,9, term="high")], - universe_of_discourse=[0, 9])) + FS.add_linguistic_variable("playerCardsValue", LinguisticVariable([ + TriangleFuzzySet(0,0,12, term="low"), + TriangleFuzzySet(11,14,17, term="average"), + TriangleFuzzySet(12,21,21, term="high")], + universe_of_discourse=[0, 21])) FS.add_linguistic_variable("countedCardsValue", LinguisticVariable([ TriangleFuzzySet(-20,-20,0, term="low"), @@ -271,23 +271,23 @@ def getSoftHandDecision(dealerCard, playerCardsVal, countedCardsVal, playerCards if playerCardsNum == 2: FS.add_rules([ - "IF (playerCardValue IS average) AND (dealerCardValue IS average) THEN (decision IS double down)", - "IF (playerCardValue IS high) THEN (decision IS Stand)", - "IF (playerCardValue IS average) AND (dealerCardValue IS high) THEN (decision IS hit)", + "IF (playerCardsValue IS average) AND (dealerCardValue IS average) THEN (decision IS double down)", + "IF (playerCardsValue IS high) THEN (decision IS stand)", + "IF (playerCardsValue IS average) AND (dealerCardValue IS high) THEN (decision IS hit)", "IF (playerCardValue IS low) AND (dealerCardValue IS low) THEN (decision IS hit)", ]) else: FS.add_rules([ - "IF (playerCardValue IS high) THEN (decision IS Stand)", - "IF (playerCardValue IS low) THEN (decision IS hit)", - "IF (playerCardValue IS average) AND (dealerCardValue IS high) THEN (decision IS Hit)", - "IF (playerCardValue IS average) AND (dealerCardValue IS average) AND (countedCardsValue IS high) THEN (decision IS Stand)", - "IF (playerCardValue IS average) AND (dealerCardValue IS average) AND (countedCardsValue IS low) THEN (decision IS Hit)" + "IF (playerCardsValue IS high) THEN (decision IS stand)", + "IF (playerCardsValue IS low) THEN (decision IS hit)", + "IF (playerCardsValue IS average) AND (dealerCardValue IS high) THEN (decision IS Hit)", + "IF (playerCardsValue IS average) AND (dealerCardValue IS average) AND (countedCardsValue IS high) THEN (decision IS stand)", + "IF (playerCardsValue IS average) AND (dealerCardValue IS average) AND (countedCardsValue IS low) THEN (decision IS Hit)" ]) FS.set_variable("dealerCardValue", dealerCard) - FS.set_variable("playerCardValue", playerCardsVal) - FS.set_variable("countedCardsValue", playerCardsNum) + FS.set_variable("playerCardsValue", playerCardsVal) + FS.set_variable("countedCardsValue", playerCardsVal) result = FS.inference() decision_terms = [(i.get_term(), FS.get_fuzzy_set('decision', i.get_term()).get_value(result['decision'])) for i in FS.get_fuzzy_sets('decision')] diff --git a/cards.py b/cards.py index 1de2fc5..a083f81 100644 --- a/cards.py +++ b/cards.py @@ -83,6 +83,8 @@ def AI(hand: list, face_up: str, losses_in_row: int) -> str: """ cards_count = len(hand) + highlow = count_highlow(hand) + evaluation = cards_eval(hand) if len(evaluation) != 1: evaluation = evaluation[1] @@ -90,11 +92,9 @@ def AI(hand: list, face_up: str, losses_in_row: int) -> str: evaluation = evaluation[0] decision = '' if 'ace' in hand: - decision = getSoftHandDecision(face_up, evaluation, cards_count) + decision = getSoftHandDecision(face_up, evaluation, highlow,cards_count) else: - decision = getHardHandDecision(face_up, evaluation, cards_count) - - breakpoint() + decision = getHardHandDecision(face_up, evaluation, highlow,cards_count) return decision def show_game_state(player_hand: list, dealer_hand: list, splited: bool, decision: str='') -> None: @@ -158,7 +158,8 @@ def blackjack(shoe: iter, dealer_hand: list=[], player_hand: list=[], bet: int=1 elif decision == 'surrender': break elif decision == 'stand': - break + dealer_hand.append(next(shoe)) + dealer_value = dealer(dealer_hand, shoe) player_value = max(cards_eval(player_hand))