WIP
This commit is contained in:
parent
aed214bac5
commit
fca596c327
@ -251,11 +251,11 @@ def getSoftHandDecision(dealerCard, playerCardsVal, countedCardsVal, playerCards
|
|||||||
TriangleFuzzySet(6,11,11, term="high")],
|
TriangleFuzzySet(6,11,11, term="high")],
|
||||||
universe_of_discourse=[0, 11]))
|
universe_of_discourse=[0, 11]))
|
||||||
|
|
||||||
FS.add_linguistic_variable("playerCardValue", LinguisticVariable([
|
FS.add_linguistic_variable("playerCardsValue", LinguisticVariable([
|
||||||
TriangleFuzzySet(0,0,5, term="low"),
|
TriangleFuzzySet(0,0,12, term="low"),
|
||||||
TriangleFuzzySet(4,6,8, term="average"),
|
TriangleFuzzySet(11,14,17, term="average"),
|
||||||
TriangleFuzzySet(7,9,9, term="high")],
|
TriangleFuzzySet(12,21,21, term="high")],
|
||||||
universe_of_discourse=[0, 9]))
|
universe_of_discourse=[0, 21]))
|
||||||
|
|
||||||
FS.add_linguistic_variable("countedCardsValue", LinguisticVariable([
|
FS.add_linguistic_variable("countedCardsValue", LinguisticVariable([
|
||||||
TriangleFuzzySet(-20,-20,0, term="low"),
|
TriangleFuzzySet(-20,-20,0, term="low"),
|
||||||
@ -271,23 +271,23 @@ def getSoftHandDecision(dealerCard, playerCardsVal, countedCardsVal, playerCards
|
|||||||
|
|
||||||
if playerCardsNum == 2:
|
if playerCardsNum == 2:
|
||||||
FS.add_rules([
|
FS.add_rules([
|
||||||
"IF (playerCardValue IS average) AND (dealerCardValue IS average) THEN (decision IS double down)",
|
"IF (playerCardsValue IS average) AND (dealerCardValue IS average) THEN (decision IS double down)",
|
||||||
"IF (playerCardValue IS high) THEN (decision IS Stand)",
|
"IF (playerCardsValue 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 high) THEN (decision IS hit)",
|
||||||
"IF (playerCardValue IS low) AND (dealerCardValue IS low) THEN (decision IS hit)",
|
"IF (playerCardValue IS low) AND (dealerCardValue IS low) THEN (decision IS hit)",
|
||||||
])
|
])
|
||||||
else:
|
else:
|
||||||
FS.add_rules([
|
FS.add_rules([
|
||||||
"IF (playerCardValue IS high) THEN (decision IS Stand)",
|
"IF (playerCardsValue IS high) THEN (decision IS stand)",
|
||||||
"IF (playerCardValue IS low) THEN (decision IS hit)",
|
"IF (playerCardsValue IS low) THEN (decision IS hit)",
|
||||||
"IF (playerCardValue IS average) AND (dealerCardValue IS high) THEN (decision IS Hit)",
|
"IF (playerCardsValue 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 (playerCardsValue 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 average) AND (dealerCardValue IS average) AND (countedCardsValue IS low) THEN (decision IS Hit)"
|
||||||
])
|
])
|
||||||
|
|
||||||
FS.set_variable("dealerCardValue", dealerCard)
|
FS.set_variable("dealerCardValue", dealerCard)
|
||||||
FS.set_variable("playerCardValue", playerCardsVal)
|
FS.set_variable("playerCardsValue", playerCardsVal)
|
||||||
FS.set_variable("countedCardsValue", playerCardsNum)
|
FS.set_variable("countedCardsValue", playerCardsVal)
|
||||||
|
|
||||||
result = FS.inference()
|
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')]
|
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')]
|
||||||
|
11
cards.py
11
cards.py
@ -83,6 +83,8 @@ def AI(hand: list, face_up: str, losses_in_row: int) -> str:
|
|||||||
"""
|
"""
|
||||||
cards_count = len(hand)
|
cards_count = len(hand)
|
||||||
|
|
||||||
|
highlow = count_highlow(hand)
|
||||||
|
|
||||||
evaluation = cards_eval(hand)
|
evaluation = cards_eval(hand)
|
||||||
if len(evaluation) != 1:
|
if len(evaluation) != 1:
|
||||||
evaluation = evaluation[1]
|
evaluation = evaluation[1]
|
||||||
@ -90,11 +92,9 @@ def AI(hand: list, face_up: str, losses_in_row: int) -> str:
|
|||||||
evaluation = evaluation[0]
|
evaluation = evaluation[0]
|
||||||
decision = ''
|
decision = ''
|
||||||
if 'ace' in hand:
|
if 'ace' in hand:
|
||||||
decision = getSoftHandDecision(face_up, evaluation, cards_count)
|
decision = getSoftHandDecision(face_up, evaluation, highlow,cards_count)
|
||||||
else:
|
else:
|
||||||
decision = getHardHandDecision(face_up, evaluation, cards_count)
|
decision = getHardHandDecision(face_up, evaluation, highlow,cards_count)
|
||||||
|
|
||||||
breakpoint()
|
|
||||||
return decision
|
return decision
|
||||||
|
|
||||||
def show_game_state(player_hand: list, dealer_hand: list, splited: bool, decision: str='') -> None:
|
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':
|
elif decision == 'surrender':
|
||||||
break
|
break
|
||||||
elif decision == 'stand':
|
elif decision == 'stand':
|
||||||
break
|
dealer_hand.append(next(shoe))
|
||||||
|
dealer_value = dealer(dealer_hand, shoe)
|
||||||
|
|
||||||
player_value = max(cards_eval(player_hand))
|
player_value = max(cards_eval(player_hand))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user