Exemplo n.º 1
0
def main():
    '''Main function'''
    player1 = Player("Alice", 5)
    player2 = Player("Bob", 5)
    print('{} ({}) and {} ({}) are going to play 100 games!'.format(player1.name, player1.skill, player2.name, player2.skill))
    print('{:^10}{:^10}{:^10}'.format('Game', 'Winner', 'Rounds'))
    winners = {'Alice': 0, 'Tie': 0, 'Bob': 0}
    for i in range(1, 101):
        winner, rounds = play_game(player1, player2)
        winners[winner] += 1
        print('{:^10}{:^10}{:^10}'.format(i, winner, rounds))
    print(winners)
Exemplo n.º 2
0
    #print player.toString()


def waitForAction(player):
    action = raw_input("Stick or twist? ")
    if action.lower()[0] == 's':
        player.isStuck = True
    else:
        twist(player)


name = raw_input('What is your name? ')

play = 'y'
while play.lower()[0] == 'y':
    dealer = Player('Dealer')
    player = Player(name)
    deck = Deck()

    #for card in deck.cards:
    #    print card.toString()

    #Deal cards
    for i in range(2):
        twist(player)
        twist(dealer)

    while not (player.isStuck or player.isBust()):
        print player.toString()
        waitForAction(player)
Exemplo n.º 3
0
                         cardname)
    if true:
        used_card.move(side(action, 'x'), side(action, 'y'))
    else:
        used_card.wait
    field_refresh(players, n, m, field)


card1 = Card("spearman1", 10, [0.1, 0.1, 0.1, 0.1], [1, 1, 1, 1], [1, 1, 1], 2)
card2 = Card("swordsman", 15, [0.3, 0.3, 0.3, 0.3], [2, 2, 2, 2],
             [0.8, 0.8, 0.8], 3)
card3 = Card("cavalryman", 20, [0.5, 0.5, 0.5, 0.5], [5, 2, 3, 1],
             [0.6, 0.6, 0.6], 3)
player1 = Player("User", {
    'spearman': card1,
    'swordsman': card2,
    'cavalryman': card3
})

j = 0

for i in player1.card.values():
    i.setCoord(5, j)
    j += 1
card4 = Card("spearman", 10, [0.1, 0.1, 0.1, 0.1], [1, 1, 1, 1], [1, 1, 1], 2)
card5 = Card("swordsman", 15, [0.3, 0.3, 0.3, 0.3], [2, 2, 2, 2],
             [0.8, 0.8, 0.8], 3)
card6 = Card("cavalryman", 20, [0.5, 0.5, 0.5, 0.5], [5, 2, 3, 1],
             [0.6, 0.6, 0.6], 3)
player2 = Player("Enemy", {
    'spearman': card4,
Exemplo n.º 4
0
		      (_,._)  ( `' )  <  >  (_)+(_)
		        /\     `.,'    \/      |

"""

print blackjack
print symbols
name = raw_input("What is your name? ")
chip = input("How many starter chips do you want? ")
while type(chip) != int:
    chip = input("Please enter an integer. ")
bet = input("How much do you want to wager each time? ")
while type(bet) != int:
    bet = input("Please put a integer.")
myDeck = Deck()
player = Player(name, chip, bet)
dealer = Dealer()


def start_game():
    myDeck.create()
    myDeck.shuffle()
    myDeck.deal(player, dealer)


def lose():
    player.chips -= player.bet
    print """
 __   _____  _   _   _     ___  ____  _____     _______           _______  
 \ \ / / _ \| | | | | |   / _ \/ ___|| ____|   / /_   _|         |_   _\ \ 
  \ V / | | | | | | | |  | | | \___ \|  _|    | |  | |             | |  | |
Exemplo n.º 5
0
def play_game():
    player_name = input("What is your name? ")
    print(f'Welcome {player_name}!\n')
    player = Player(player_name)

    game_on = True
    while game_on:
        player.clear_hand()
        print(player)

        # Create a deck of 52 cards, Shuffle the deck
        deck = Deck()
        deck.shuffle()

        dealer = Player("Dealer")

        # Ask the Player for their bet
        # Make sure that the Player's bet does not exceed their available chips
        bet_amount = ask_bet(player)

        # Deal two cards to the Dealer and two cards to the Player
        dealer.add_card(deck.deal_one())
        dealer.add_card(deck.deal_one())
        player.add_card(deck.deal_one())
        player.add_card(deck.deal_one())

        hitting = True
        player_bust = False
        print('Player Hitting')
        while hitting and not player_bust:
            # Show only one of the Dealer's cards, the other remains hidden
            # Show both of the Player's cards
            show_table(dealer, player, hide=True)

            # Ask the Player if they wish to Hit, and take another card
            hit = ask_hit(player)
            if hit:
                player.add_card(deck.deal_one())
                # If the Player's hand doesn't Bust (go over 21), ask if they'd like to Hit again.
                if player.hand_value > 21:
                    print('PLAYER BUST!!!')
                    player_bust = True
            else:
                hitting = False

        if not player_bust:
            # If a Player Stands, play the Dealer's hand.
            # The dealer will always Hit until the Dealer's value meets or exceeds 17
            print('Dealer Hitting')
            while dealer.hand_value < 17:
                show_table(dealer, player, hide=True)

                dealer.add_card(deck.deal_one())
                if dealer.hand_value > 21:
                    print('DEALER BUST!!!')

        show_table(dealer, player, hide=False)

        # Determine the winner and adjust the Player's chips accordingly
        player_wins = determine_winner(dealer, player)
        if player_wins:
            player.award(bet_amount * 2)
            print(f'{player.name} WINS')
        else:
            print(f'Dealer WINS')
        print(
            f'{player.name}: {player.hand_value}, Dealer: {dealer.hand_value}')

        # Ask the Player if they'd like to play agaim

        play_again = ask_play_again()
        if not play_again or player.money <= 0:
            game_on = False
        else:
            pass
Exemplo n.º 6
0
from deck import Deck
from cards import Player
import sys
import time
from hand_calculator import handType
from compare_results import compareResults

print "~~~BACCARAT~~~"
name = raw_input("What is your name? >>> ")
player = Player(name)
gameOver = False
deck = Deck().shuffle()

while gameOver == False:
    # Making Bets
    player.bet = raw_input(
        "You have {} coins. How many would you like to bet? >>> ".format(
            player.bank))
    player.bet = int(player.bet)
    if player.bet > player.bank:
        print "Not enough mulah, chump!"
        continue
    player.bank -= player.bet

    # Deals three cards to player and dealer

    playerCards = []
    dealerCards = []

    for i in range(0, 3):
        playerCards.append(deck.draw())
Exemplo n.º 7
0
def reset():
    deck = Deck().shuffle()
    player = Player("Ray", deck)
    opponent = Player("Dealer", deck)
    return deck, player, opponent
Exemplo n.º 8
0
"""Game of War

Code by Josh Blumberg
Based on rules from: https://gamerules.com/rules/war-card-game/
"""
from cards import Card, Deck, Player
from time import sleep
from random import shuffle

# Game Setup
players = [
    Player(input(f'What is the name of player {n}: ')) for n in range(1, 3)
]
war_pile = []
game_speed = 0  # Number of seconds to pause between rounds
PLAYER_1 = 0
PLAYER_2 = 1

# Deal all of the cards
deck = Deck()
deck.shuffle()
while True:
    try:
        players[PLAYER_1].add_cards_to_bottom([deck.draw_card()])
        players[PLAYER_2].add_cards_to_bottom([deck.draw_card()])
    except IndexError:
        break

# Main game loop
while players[PLAYER_1].cards and players[
        PLAYER_2].cards:  # While both players have cards
Exemplo n.º 9
0
"""

symbols = """\033[1;31m
			                               _
			       ,'`.    _  _    /\    _(_)_
			      (_,._)  ( `' )  <  >  (_)+(_)
			        /\     `.,'    \/      |
\033[1;m
"""
print blackjack
print symbols

name = raw_input("What is your name? ")  # Asks user what their name is

myDeck = Deck()  # create Deck object
player = Player(name)  # create Player object
dealer = Dealer()  # create Dealer object


def start_game():  # start game function
    myDeck.create()  # creates the deck
    myDeck.shuffle()  # shuffles the deck
    myDeck.deal(player,
                dealer)  # deals the cards to the players and prints message


def the_game():  # function that plays the game
    myDeck.reset(
        player,
        dealer)  # every time the game starts/restarts, the cards are reset
    start_game()  # calls the start_game function and starts the game
import json

from flask import Flask
from flask import render_template
from flask import request, send_file

from cards import Deck, Player

blackjack_site = Flask(__name__)

player_name = 'Tanner'
player = Player(player_name)


@blackjack_site.route('/')
def blackjack_index():
    return render_template('blackjack.html')


@blackjack_site.route('/player/money')
def get_player_money():
    money = player.money
    return json.dumps({'money': money})



blackjack_site.run(host='localhost', port=8081)


# @blackjack_site.route('/devices/')
# @blackjack_site.route('/devices/<guid>')
Exemplo n.º 11
0
 def __init__(self):
     self.the_doctor = Player("The Doctor")
     self.the_master = Player("The Master")
     self.dealer = Player("Dealer")
     self.game = BlackJack([self.the_doctor, self.the_master], self.dealer)
Exemplo n.º 12
0
class BlackJackSimulation(object):
    def __init__(self):
        self.the_doctor = Player("The Doctor")
        self.the_master = Player("The Master")
        self.dealer = Player("Dealer")
        self.game = BlackJack([self.the_doctor, self.the_master], self.dealer)

    def play(self):
        print ("Starting Blackjack")
        self.game.start()
        # start off by calculating the value of the players' cards
        self.calculate_hand(self.dealer)

        for player in self.game.players:
            self.calculate_hand(player)

        # for the sake of testing, we'll loop for 5 rounds
        for x in xrange(5):
            dealer_score = self.game.get_points_for_player(self.dealer)

            if dealer_score <= 15:
                self.game.hit(self.dealer)
                self.calculate_hand(self.dealer)  # reprocess the card values

            for player in self.game.players:
                if self.game.get_points_for_player(player) <= 15:
                    self.game.hit(player)
                    self.calculate_hand(player)  # reprocess the card values

        # Show final hand
        print (
            "{0}\t\t{1}\t{2}".format(
                self.dealer.name, self.game.get_points_for_player(self.dealer), self.dealer.printable_hand()
            )
        )

        for player in self.game.players:
            print (
                "{0}\t{1}\t{2}".format(player.name, self.game.get_points_for_player(player), player.printable_hand())
            )

        print ("*" * 45)

    def calculate_hand(self, player):
        """ A helper function to assist the bot in knowing when to hit
            by selecting the value of aces
        """
        total = sum([self.game.get_point_values(card) for card in player.hand if card.value != "A"])

        aces = [card for card in player.hand if card.value == "A"]

        # this is a crude method, this is NOT supposed to be a fully functioning
        # game. Just a rough demo of the code to create a game.
        def handle_aces(total, aces):
            ace_count = len(aces)

            if total <= 11 - ace_count:
                if ace_count:
                    # set the first ace to 11, the rest to 1
                    self.game.set_point_value(aces[0], 11)
                    [self.game.set_point_value(card, 1) for card in aces[1:]]

                return total + 10 + ace_count
            else:
                if ace_count:
                    [self.game.set_point_value(card, 1) for card in aces]
                return total + ace_count

        total = handle_aces(total, aces)

        return total