Sale!

Blackjack Game – Python Programming

Rs.5,999.00Rs.8,999.00

Project Development Process

It’s an Python-programming – project internship, which in advance blended mode comes bundled with Tic Tac Toe Project.

Develop your Blackjack game in two phases. The first phase will concentrate on implementing the basic logic of Blackjack while the second phase will focus on building a more full-featured version. In phase one, you will use buttons to control the game and print the state of the game to the console using print statements. In the second phase, you will replace the print statements by drawing images and text on the canvas and add some extra game logic.

In phase one, testing templates for four of the steps will be provided. The templates are designed to check whether your class implementations work correctly. You should copy your class definition into the testing template and compare the console output generated by running the template with the provided output. If the output matches, it is likely that your implementation of the class is correct.

In the second phase of your implementation, you will add five features. For those involving drawing with global variables, remember to initialize these variables to appropriate values (like creating empty hands for the player and dealer) just before starting the frame.

Object Design for Simulating Blackjack

Elements of the game, such as the player, hand, and card, as examples for object modeling will be used. Designing the entire simulation may not be possible. So focus over the elements of this game as they have some nuance, but aren’t terribly complex.

The cards are relatively simple, immutable objects. There are a variety of modeling techniques available. Cards fall into a simple class hierarchy of the number cards, face cards, and the Ace. There are simple containers, including hands of card instances, and decks of cards as well. These are stateful collections with cards being added and removed. There are a number of ways to implement this in Python and we’ll look at many alternatives. We also need to look at the player as a whole. A player will have a sequence of hands, as well as a betting strategy and a Blackjack play strategy. This is a rather complex composite object.

Clear
SKU: 10003 Category:

Description

Introduction

Blackjack is a popular card game. Cards in Blackjack have the following values: an ace may be valued as either 1 or 11 (player’s choice), face cards (kings, queens and jacks) are valued at 10 and the value of the remaining cards corresponds to their number. During a round of Blackjack, the players play against a dealer with the goal of building a hand (a collection of cards) whose cards have a total value that is higher than the value of the dealer’s hand, but not over 21. (A round of Blackjack is also sometimes referred to as a hand.)

The game logic for our simplified version of Blackjack is as follows. The player and the dealer are each dealt two cards initially with one of the dealer’s cards being dealt face down (his hole card). The player may then ask for the dealer to repeatedly “hit” his hand by dealing him another card. If, at any point, the value of the player’s hand exceeds 21, the player is “busted” and loses immediately. At any point prior to busting, the player may “stand” and the dealer will then hit his hand until the value of his hand is 17 or more. (For the dealer, aces count as 11 unless it causes the dealer’s hand to bust). If the dealer busts, the player wins. Otherwise, the player and dealer then compare the values of their hands and the hand with the higher value wins.The dealer wins ties in our version.

blackjack

Sample Design Code

# Sample program simulates Blackjack game.

from random import randrange

def main():
printIntro()
player_hand = player()
dealer_hand = dealer()
player_win, dealer_win = compare_between(player_hand, dealer_hand)
printResult(player_hand, dealer_hand, player_win, dealer_win)

def printIntro():
print(“Blackjack (twenty-one) is a casino game played with cards.”)
print(“the goal of game is to draw cards that total as close to 21 points, as possibale”)
print(“without going over( whose hand > 21 will bust). All face cards count as 10 points,”)
print(“aces count as 1 or 11, and all other cards count their numeric value.”)
print(“\nFirstly, your turn:”)

def player():
hand = []
ans = “hit”
hand.append(card())
# Ask user whether Hit or Stand?
# Condition True, if user want to Hit.
while ans[0] == “h” or ans[0] == “H”:
hand.append(card())
hand = eval_ace(hand)
print(“Your hand: {0} total = {1}”.format(hand, sum(hand)))
if bust(hand):
break
if blackjack(hand):
break
ans = input(“Do you want to Hit or Stand (H or S)? “)
return hand

def card():
# get arbitrary card from 2 to 11.
shuffle_card = randrange(2, 11 + 1)
return shuffle_card

def eval_ace(hand):
# Determine Ace = 1 or 11, relying on total hand.
total = sum(hand)
for ace in hand:
if ace == 11 and total > 21:
# at position, where Ace == 11, replace by Ace == 1.
position_ace = hand.index(11)
hand[position_ace] = 1
return hand

def bust(hand):
# Condition True: if the hand of player (or dealer) > 21.
total = sum(hand)
if total > 21:
return True

def blackjack(hand):
# Condition True: if the hand of player (or dealer) == 21.
total = sum(hand)
if total == 21:
return True

def dealer():
hand = []
hand.append(card())
while sum(hand) < 18:
hand.append(card())
hand = eval_ace(hand)
return hand

def compare_between(player, dealer):
total_player = sum(player)
total_dealer = sum(dealer)
player_bust = bust(player)
dealer_bust = bust(dealer)
player_blackjack = blackjack(player)
dearler_blackjack = blackjack(dealer)
player_win = 0
dealer_win = 0
# when player (dealer) bust.
if player_bust:
if not dearler_blackjack and total_dealer < 21:
dealer_win += 1
if dealer_bust:
if not player_blackjack and total_player < 21:
player_win += 1
if player_bust and dealer_bust:
if total_player > total_dealer:
player_win += 1
elif total_dealer > total_player:
dealer_win += 1
else:
player_win == dealer_win
# when player (dealer) get blackjack.
if player_blackjack:
player_win += 1
if dearler_blackjack:
dealer_win += 1
if player_blackjack and dearler_blackjack:
player_win == dealer_win
# when total hand of player (dealer) < 21.
if total_player < 21 and total_dealer < 21:
if total_player > total_dealer:
player_win += 1
elif total_dealer > total_player:
dealer_win += 1
else:
player_win == dealer_win
return player_win, dealer_win

def printResult(player_hand, dealer_hand, player_win, dealer_win):
print(“\nWe have the result: “)
print(“Player has: {0} total = {1}”.format(player_hand, sum(player_hand)))
print(“Dealer has: {0} total = {1}”.format(dealer_hand, sum(dealer_hand)))
print(“player: {} | dealer: {}”.format(player_win, dealer_win))

if __name__ == “__main__”: main()

Additional information

Type

Basic Blended, Advanced Blended

Reviews

There are no reviews yet.

Be the first to review “Blackjack Game – Python Programming”

Your email address will not be published. Required fields are marked *