Ejemplo n.º 1
0
    def __init__(self, hand=None, parameters=None):
        super().__init__(ID="simple", type=["Simple"])
        self.blackjack_value = 21
        self.maxCard = 11
        self.bust_value = self.blackjack_value + 1
        self.hand = hand

        if parameters is None:
            self.set_parameters(setting="default")
        if hand is None:
            self.hand = Hand(self.ID)
Ejemplo n.º 2
0
def hands_to_string(dealer_hand: Blackjack.Hand, player_hand: Blackjack.Hand,
                    hide_dealer) -> str:
    output = "Current Hands:\n"
    output += "Dealer:\n"
    output += "{}".format(dealer_hand.cards_string(hide_dealer))
    if not hide_dealer:
        output += "**({})**".format(dealer_hand.curr_value)
    output += "\nPlayer:\n"
    output += "{}**({})**\n".format(player_hand.cards_string(False),
                                    player_hand.curr_value)
    return output
Ejemplo n.º 3
0
    def blackjackChanceTesting(CI, testIters):
        CCAI_Hand = Hand("CC_AI")
        players = {"CC_AI": CCAI_Hand, "dealer": Dealer_Hand("dealer")}
        blackjack = Blackjack(players)
        CCAI_Interface = Counting_Interface(blackjack, CI, CCAI_Hand)
        # Get the game state then calc chances
        for x in range(testIters):
            print()

            blackjack.display_game()
            gameState = CCAI_Interface.getGameState()

            hand = gameState[0]
            handValue = gameState[1]
            dealer_hand = gameState[2]
            dealerValue = gameState[3]
            AI_Winning = hand == dealer_hand

            CI.decrement_cards(hand, dealer_hand)
            CI.displayCardRecord()
            chances = CI.calcChances(hand, handValue, dealer_hand, dealerValue,
                                     AI_Winning)
            for key in chances.keys():
                print(key, chances[key])
            blackjack.reset()
Ejemplo n.º 4
0
class Simple_AI(Agent):
    def __init__(self, hand=None, parameters=None):
        super().__init__(ID="simple", type=["Simple"])
        self.blackjack_value = 21
        self.maxCard = 11
        self.bust_value = self.blackjack_value + 1
        self.hand = hand

        if parameters is None:
            self.set_parameters(setting="default")
        if hand is None:
            self.hand = Hand(self.ID)

    def set_parameters(self, setting="default"):
        if setting == "default":
            self.win_margin_threshold = 1
            self.bust_threshold = 3
            self.min_hand_threshold = 15
        elif setting == "aggressive":
            self.win_margin_threshold = 3
            self.bust_threshold = 7
            self.min_hand_threshold = 18
        elif setting == "passive":
            self.win_margin_threshold = 0
            self.bust_threshold = 1
            self.min_hand_threshold = 13

    # returns decision to hit or not -> true => hit, false => stand
    # stands if blackjacked or winning by a sufficient amount
    # otherwise hits if cannot go bust, or under the bust margin threshold
    def get_move(self, all_players):
        next_best_hand = self.get_best_hand(all_players)
        best_player_value = next_best_hand.get_value()
        best_player_stood = next_best_hand.has_stood

        hand_value = self.hand.get_value()
        win_margin = hand_value - best_player_value

        # if blackjack'd or winning by a sufficient amount
        if hand_value == self.blackjack_value or \
           (win_margin > self.win_margin_threshold and hand_value > self.min_hand_threshold):
            return Moves.STAND
        # If cannot go bust, or edge case satisfied then hit
        elif (hand_value < (self.bust_value - self.maxCard)
              or self.edge_move_calc(hand_value, best_player_value)):
            return Moves.HIT
        return Moves.STAND

    # HAVE A LOOK AT THIS
    def edge_move_calc(self, hand_value, best_value):
        bustDiff = abs(hand_value -
                       self.bust_value)  # how far off being bust SAI is
        LTBestPlayer = hand_value < best_value and best_value <= 21
        if LTBestPlayer or bustDiff <= self.bust_threshold:
            return True
        return False

    def update_end_game(self, new_cards):
        pass
Ejemplo n.º 5
0
 def __init__(self, parameters=None, hand=None):
     super().__init__(ID="cc_ai")
     self.parameters = parameters
     self.Hand = hand
     if parameters is None:
         self.set_parameters(setting="default")
     if hand is None:
         self.Hand = Hand(self.ID)
Ejemplo n.º 6
0
 def start_game(self):
     # создаем колоду
     d = Deck()
     # задаем "руки" для игрока и дилера
     player_hand = Hand("Player")
     dealer_hand = Hand("Dealer")
     # сдаем две карты игроку
     player_hand.add_card(d.deal_card())
     player_hand.add_card(d.deal_card())
     # сдаем одну карту дилеру
     dealer_hand.add_card(d.deal_card())
     self.textEdit.append(str(dealer_hand))
     self.textEdit.append(str("=" * 20))
     self.textEdit.append(str(player_hand))
     # Флаг проверки необходимости продолжать игру
     in_game = True
     # набирать карты игроку имеет смысл только если у него на руке меньше 21 очка
     self.textEdit.append("Hit or stand? (h/s) ")
     self.pushButton_5.clicked.connect(
         lambda: self.game(d, player_hand, dealer_hand, in_game))
Ejemplo n.º 7
0
Archivo: NN.py Proyecto: WillyGG/NEA
    def __init__(self,
                 setting="default",
                 hand=None,
                 restore_type="default",
                 Training=True,
                 auto_load=True):
        super().__init__(ID="nn", extra_type=["nn"])
        self.rnn_state = None
        self.sess = None

        self.parameters = self.set_parameters(setting=setting)
        self.train_params = self.set_training_params(setting=setting)

        if hand is None:
            self.Hand = Hand(self.ID)

        self.initalise_NN(Training)
        self.start_session()

        if auto_load:
            self.load_model(restore_type)
 def __init__(self, hand=None):
     super().__init__(ID="rand", type=["Random"])
     self.hand = hand
     if hand is None:
         self.hand = Hand(self.ID)
Ejemplo n.º 9
0
from tkinter import *
from Blackjack import DHand, Hand

from PIL import ImageTk, Image

cards = ["d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "d10", "dj", "dq", "dk", "da", "s2", "s3", "s4", "s5", "s6",
         "s7", "s8", "s9", "s10", "sj", "sq", "sk", "sa", "h2", "h3", "h4", "h5", "h6", "h7", "h8", "h9", "h10", "hj",
         "hq", "hk", "ha", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "cj", "cq", "ck", "ca"]
values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
removed = []

dea = DHand.DHand()
play = Hand.Hand()


# stand method will just be continue (doing it in the gui)
# make player class after sure initial blackjack works

class GUI():
    def __init__(self, window):
        self.window = window
        bgcolor = "#ff0000"
        window.title("Blackjack")
        window.geometry("1280x800")
        window.resizable(0, 0)

        self.frame = Frame(master=window, bg=bgcolor)
        self.frame.pack_propagate(0)
        self.frame.pack(fill=BOTH, expand=1)
Ejemplo n.º 10
0
 def construct_hands(self):
     hands = {}
     for name in self.usernames:
         hands[name] = Hand(name)
     return hands
Ejemplo n.º 11
0
# Testing template for the Hand class
from Blackjack import Card, Hand

c1 = Card("S", "A")
c2 = Card("C", "2")
c3 = Card("D", "T")
print c1, c2, c3
print type(c1), type(c2), type(c3)

test_hand = Hand()
print test_hand

test_hand.add_card(c1)
print test_hand

test_hand.add_card(c2)
print test_hand

test_hand.add_card(c3)
print test_hand

print type(test_hand)

###################################################
# Output to console
# note that the string representation of a hand will
# vary based on how you implemented the __str__ method

# SA C2 DT
# <class '__main__.Card'> <class '__main__.Card'> <class '__main__.Card'>
# Hand contains