Exemple #1
0
def get_possible_actions(game):
    global values

    hand = game._get_current_hand()
    top_cards = game.top

    # List of lists
    possible_cards_to_drop = get_possible_cards_to_drop(hand)

    sars = []

    if get_hand_sum(hand) <= 7:
        state_key = get_state_key_for_game(hand)
        # expected_value, hand, dropped_cards, pickup_from_deck=True, card_to_pickup_from_top=None, show=False
        sar_show = SAR(values[state_key], hand, [], False, None, True)
        sars.append(sar_show)

    ## Check normal moves
    for cards_to_drop in possible_cards_to_drop:
        hand_after_drop = list(filter(lambda x: x not in cards_to_drop, hand))
        # SARs for pickup from deck
        # for rank in range(1, 14):
        #     for suit in range(4):

        # Actually, we only want to consider SARs for the actions we have control over.
        # In this case, that means all of the possible cards we could pick up should be part
        #   of a single action piece - namely, picking up from the deck.

        # hand_after_pickup = list(hand_after_drop) + [card_to_pickup_from_deck]
        # state_key = get_state_key_for_game(hand, cards_to_drop, False)

        sum_of_deck_values = 0
        # Get value for every possible card you could pick up from the deck, then use that to calculate
        # The overall expected value
        d = deck_of_cards.DeckOfCards().deck
        # TODO: should we count cards? (exclude cards in top?) for now, no.
        for c in d:
            hand_after_pickup = hand_after_drop + [c]
            deck_card_key = get_state_key_for_game(hand_after_pickup, False)
            deck_card_value = values[deck_card_key]
            sum_of_deck_values = sum_of_deck_values + deck_card_value

        expected_value = sum_of_deck_values / 52  # average value of all possible cards you could pick up from deck
        # expected_value, hand, dropped_cards, pickup_from_deck=True, card_to_pickup_from_top=None, show=False
        sar = SAR(expected_value, hand, cards_to_drop, True, None, False)
        sars.append(sar)

        # SARs for pickup from top
        for card in top_cards:
            # hand_after_drop = filter(lambda x: x not in cards_to_drop, hand)

            hand_after_pickup = list(hand_after_drop) + [card]
            state_key = get_state_key_for_game(hand_after_pickup, False)
            expected_value = 1 * values[state_key]
            # expected_value, hand, dropped_cards, pickup_from_deck=True, card_to_pickup_from_top=None, show=False
            sar = SAR(expected_value, hand, cards_to_drop, True, card, False)
            sars.append(sar)

    return sars
Exemple #2
0
 def draw_card(self):
     if len(self.deck_obj.deck) == 0:
         self.deck_obj = deck_of_cards.DeckOfCards()
         self.number_decks += 1
     card = self.deck_obj.give_random_card()
     card.image_path = "./PNG/" + \
         str(card.rank if ranks.get(card.rank) is None else ranks.get(
             card.rank)) + suits_set.get(card.suit) + ".png"
     if card.rank == 1:
         card.value = 14
     return card
Exemple #3
0
    def make_turn(self, cardsToDrop, pickupFromDeck=True, cardToPickup=None):
        # TODO validate turn
        assert (isinstance(cardsToDrop, list))

        self.open = cardsToDrop + self.open

        # Remove cards from the hand
        hand = self._get_current_hand()

        assert (all([c in hand for c in cardsToDrop]))

        for cardToDrop in cardsToDrop:
            for cardInHand in hand:
                if (cardToDrop.suit
                        == cardInHand.suit) and (cardToDrop.rank
                                                 == cardInHand.rank):
                    hand.remove(cardInHand)
                    break

        # Pickup card
        if (pickupFromDeck):
            # if no more cards, reset the discarded cards
            if len(self.deck) == 0:
                new_deck = deck_of_cards.DeckOfCards()
                new_deck.deck = self.open
                self.deck = new_deck.shuffle_deck()

            hand.append(self.deck.pop(0))
        else:
            hand.append(cardToPickup)

        # update turn counter
        if self.turn == 0:
            # If it is player 1's turn which is now over, we can update
            self.turn_count = self.turn_count + 1

        # update turn
        self.turn = (self.turn + 1) % 2

        # update top cards
        self.top = cardsToDrop

        # sort the hands
        sort_hand(self.handOne)
        sort_hand(self.handTwo)

        return 0
Exemple #4
0
    def __init__(self, print=False):
        # Hands
        self.handOne = []
        self.handTwo = []

        # Counter for number of turns made (a turn is where both players have played)
        self.turn_count = 0

        # player 1 = 0, player 2 = 1
        # Left of the dealer goes first
        self.turn = 1

        # The open cards which have been thrown, front cards are most recent
        self.open = []

        # The top card(s) on the open list
        self.top = []

        # Shuffle a new deck of cards
        self.deck = deck_of_cards.DeckOfCards().shuffle_deck()

        # By default, don't print game information
        self.print = print

        # Deal 7 cards
        for i in range(7):
            self.handTwo.append(self.deck.pop(0))
            self.handOne.append(self.deck.pop(0))

        # sort the hands
        sort_hand(self.handOne)
        sort_hand(self.handTwo)

        # Open the top card
        top_card = self.deck.pop(0)
        self.open = [top_card]
        self.top = [top_card]
Exemple #5
0
def test_shorthand():
    deck = deck_of_cards.DeckOfCards().shuffle_deck()
    card_names = [c.name for c in get_cards_by_shorthand(deck, '2c 3d jh')]
    assert(card_names == ['2 of clubs', '3 of diamonds', 'Jack of hearts'])
    return
Exemple #6
0
def get_some_cards():
	return deck_of_cards.DeckOfCards().shuffle_deck()
Exemple #7
0
 def __init__(self):
     self.table = []
     self.number_decks = 0
     self.trys = 1
     self.deck_obj = deck_of_cards.DeckOfCards()
Exemple #8
0
from deck_of_cards import deck_of_cards

human_cards = [] #human will get 2 cards afterwards
comp_cards = [] #comp will get 2 cards afterwards
flop = [] #will get a card if both players check
river = [] #will get another card

deck_obj = deck_of_cards.DeckOfCards()
deck_obj.shuffle_deck()

##.name is a function used to print card's name as a string##
print("Player 1 cards: ")
for i in range(2): #giving cards to human
    human_cards.append(deck_obj.give_random_card())
    print(human_cards[i].name)

print("\nPlayer 2 cards: ")
for j in range(2): #giving cards to computer
    comp_cards.append((deck_obj.give_random_card()))
    print(comp_cards[j].name)

print("\nPLAYER 1:")
check1 = input("Check(c) or Fold(f): ")
if check1 == 'c':
    flop.append(deck_obj.give_first_card())
    print("Flop: ", flop[0].name)

print("\nPLAYER 2:")
check2 = input("Check(c) or Fold(f): ")
if check2 == 'c':
    flop.append(deck_obj.give_first_card())