Example #1
0
def practice_recursive_war():
    d = create_deck()

    # Split an unshuffled into 2 hands that should be in the exact same order as each other.
    h1 = d[0:26]
    h2 = d[26:]

    # TODO: return a value from war() that tells us who won or if we got a tie.
    # assert result == tie
    war(h1, h2)
def simulate_games(deck, attack_sequence, samples=1000):
    damage_samples = []
    deck = create_deck(deck)

    for _ in range(samples):
        game = Game(deck)
        game.shuffle()
        for attack in attack_sequence:
            game.attack(**attack)

        damage_samples.append(game.average_bonus())

    return damage_samples
Example #3
0
def main_program():
    """
    :return: the table output
    """

    res = {
        'Pair': 0,
        'Two-pairs': 0,
        'Flush': 0,
        'High-card': 0,

    }

    header = ['# of hands', 'pairs', '%', '2 pairs', '%', 'flushes', '%', 'high card', '%']
    print('%10s %11s %3s %13s %3s %12s %3s %14s %3s' % (tuple(header)))

    for i in range(NUM_OF_HANDS_IN_TABLE):
        deck = deck_of_cards.create_deck()
        for k in range(CARDS_IN_ONE_HAND):
            hands = deck_of_cards.deal_cards(deck)
            # Replicate to make cards in both hands
            for j in range(2):
                hand = hands[5 * j:5 * j + 5]

                if poker_hand.check_pair(hand) == IS_PAIR:
                    res['Pair'] += 1
                elif poker_hand.check_pair(hand) == IS_TWO_PAIRS:
                    res['Two-pairs'] += 1
                else:
                    if poker_hand.check_flush(hand):
                        res['Flush'] += 1
                    else:
                        res['High-card'] += 1

        if (i + 1) % 1000 == 0:
            # only consider when the number of hands less than or equal to 100000
            # and divisible by 1000 (10,000; 20,000; ... ;100,000)
            percent = {}

            for key in res.keys():
                percent[key] = res[key] / i / 10 * 100
                # Calculate the percent of kinds of cards

                num_hands = (i + 1) * 10
                # the number of hands run from 10,000 to 100,000 and distance is 10,000

            print('{:>10,} {:>11d} {:>05.2f} {:>11d} {:>05.2f} {:>10d} {:>05.2f} {:>12d} {:>05.2f}'
                  .format(num_hands, res['Pair'], percent['Pair'],
                          res['Two-pairs'], percent['Two-pairs'], res['Flush'],
                          percent['Flush'], res['High-card'], percent['High-card']))
Example #4
0
def practice_semi_recursive_war():
    d = create_deck()

    # Split an unshuffled into 2 hands that should be in the exact same order as each other.
    h1 = d[0:26]
    h2 = d[26:]

    # Take the bottom thirteen cards from h1 and move them to h2.
    h3 = h1[0:13]
    h4 = h2 + h3

    # TODO: return a value from war() that tells us who won or if we got a tie.
    # assert result == tie
    war(h1, h4)
Example #5
0
def test_recursive_war():
    d = create_deck()
    assert len(d) == 52

    # Split an unshuffled into 2 hands that should be in the exact same order as each other.
    h1 = d[0:26]
    h2 = d[26:]
    assert len(h1) == 26
    assert len(h2) == 26

    # TODO: return a value from war() that tells us who won or if we got a tie.
    # assert result == tie
    war(h1, h2)
    assert len(h1) == 0
    assert len(h2) == 0
Example #6
0
def create_deck():
    suits = ["Hearts", "Spades", "Clubs", "Diamonds"]
    ranks = [
        "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King",
        "Ace"
    ]
    deck = []

    for suit in suits:
        for rank in ranks:
            deck.append(f'{rank} of {suit}')

    return deck
    cards = deck.create_deck()

    for card in cards:
        print(card)
Example #7
0
# exercise3.py

import deck

cards = deck.create_deck()

for card in cards:
    print(card)
Example #8
0
from deck import create_deck, print_deck, shuffle_deck, get_num_cards
from gameplay import create_player, prompt_bet, deal, show_hands, prompt_player_action, return_cards_to_deck
from player import Player
from dealer import Dealer

'''
Create dealer and player\
Create and shuffle the deck
Ask for the player's bet
Deal the cards
'''

dealer = Dealer()
player = create_player()
deck = create_deck()
game_over = False

while game_over == False:

	shuffle_deck(deck)
	prompt_bet(player)
	deal(deck, player, dealer)

	'''
	Player's turn:
		The flag determines when the player's turn is over. 
			If the flag is 0, the turn continues
			If the flag is 1, the turn is over
			If flag is -1, the player has busted - skip the dealer's turn
	'''
Example #9
0
import deck

baralho = deck.create_deck()
for card in baralho:
    print(card)
Example #10
0
def test_create_deck():
    assert create_deck({0: 1, 3: 2}) == [0, 3, 3]
Example #11
0
def test_create_mono_deck():
    assert create_deck({0: 2}) == [0, 0]