Player Class Represents a participant in the game of blackjack.
Must meet the following requirements: Stores the individual cards that are dealt (i.e. cannot just store the sum of the cards, you need to track which specific cards you receive) Provided methods: decide_hit(self): decides whether hit or stand by randomly selecting one of the two options.
Parameters: None
Returns: True to indicate a hit, False to indicate a stand
Must implement the following methods:
Hi!! i just need help with the player class for this. Ive added comments into my python where I need help with codes so if you could help with the red that would be great!




Working code implemented in Python and appropriate comments provided for better understanding:
Here I am attaching code for these 4 files:
Source code for player.py:
import random
class Player:
def __init__(self, name, dealer):
self.name = name
self.dealer = dealer
self.hand = []
self.__wins = 0
self.__ties = 0
self.__losses = 0
self.busted = False
def decide_hit(self):
# DO NOT MODIFY
return random.choice([True, True, False])
def deal_to(self, card_value):
"""
>>> player = Player(None, None)
>>> player.deal_to(11)
>>> player.hand
[11]
>>> player.deal_to(10)
>>> player.hand
[11, 10]
"""
self.hand.append(card_value)
if self.card_sum > 21:
self.busted = True
@property
def card_sum(self):
"""
>>> player = Player(None, None)
>>> player.deal_to(2)
>>> player.card_sum
2
>>> player.deal_to(10)
>>> player.card_sum
12
"""
return sum(self.hand)
def play_round(self):
"""
>>> from dealer import Dealer
>>> import random; random.seed(1)
>>> dealer = Dealer()
>>> dealer.shuffle_deck()
>>> player = Player(None, dealer)
We see that after the first call the play_round, we have only
hit once as dictated by decide_hit
>>> player.play_round()
>>> player.hand
[10]
After calling play_round again, decide_hit has decided to
stand
>>> player.play_round()
>>> player.hand
[10]
After a third call to play_round, we've decided to hit, but
busted!
>>> player.play_round()
>>> player.hand
[10, 8, 10]
After a final call to play_round, our hand shouldn't change
since we've already busted
>>> player.play_round()
>>> player.hand
[10, 8, 10]
"""
while not self.busted and self.decide_hit():
self.dealer.signal_hit(self)
def discard_hand(self):
"""
>>> player = Player(None, None)
>>> player.deal_to(11)
>>> player.deal_to(5)
>>> player.discard_hand()
>>> player.hand
[]
"""
self.busted = False
self.hand = []
@property
def wins(self):
return self.__wins
@property
def ties(self):
return self.__ties
@property
def losses(self):
return self.__losses
def record_win(self):
"""
>>> player = Player(None, None)
>>> player.record_win()
>>> player.wins
1
"""
self.__wins += 1
def record_loss(self):
"""
>>> player = Player(None, None)
>>> player.record_loss()
>>> player.losses
1
"""
self.__losses += 1
def record_tie(self):
"""
>>> player = Player(None, None)
>>> player.record_tie()
>>> player.ties
1
"""
self.__ties += 1
def reset_stats(self):
"""
>>> player = Player(None, None)
>>> player.record_tie()
>>> player.record_loss()
>>> player.record_win()
>>> player.reset_stats()
>>> player.ties
0
>>> player.wins
0
>>> player.losses
0
"""
self.__ties = self.__wins = self.__losses = 0
def __repr__(self):
"""
Output should include the player name, their current hand, and
their wins/ties/losses in that order
>>> player = Player("Eric", None)
>>> player.record_loss()
>>> player.record_win()
>>> player.record_win()
>>> player
Eric: [] 2/0/1
"""
return f"{self.name}: {self.hand} {self.wins}/{self.ties}/{self.losses}"
if __name__ == "__main__":
import doctest
doctest.testmod()
Code Screenshots:
![import random class Player: def __init_(self, name, dealer): self.name = name self.dealer = dealer self.hand = [] self. _wins](http://img.homeworklib.com/questions/1159f730-9bac-11eb-a795-b3d5b6d99ce2.png?x-oss-process=image/resize,w_560)

Source code for dealer.py:
from player import Player
from card_deck import CardDeck
class Dealer(Player):
def __init__(self):
super().__init__("Dealer", None)
self.deck = CardDeck()
def shuffle_deck(self):
"""
>>> import random; random.seed(1)
>>> dealer = Dealer()
>>> dealer.shuffle_deck()
>>> str(dealer.deck)[0:20]
'10 8 10 6 8 9 3 10 2'
"""
self.deck.shuffle()
def signal_hit(self, player):
"""
A method called by players when they want to hit
Player objects should pass their `self` references to this
method
Should deal one card to the player that signalled a hit
These doctests will not run properly if the `deal_to`
method
in the `Player` class is not properly implemented
>>> import random; random.seed(1)
>>> dealer = Dealer()
>>> dealer.shuffle_deck()
>>> player = Player(None, None)
>>> dealer.signal_hit(player)
>>> player.hand
[10]
"""
card = self.deck.draw()
if card:
player.deal_to(card)
def play_round(self):
"""
A dealer should hit if his hand totals to 16 or less
>>> import random; random.seed(1)
>>> dealer = Dealer()
>>> dealer.shuffle_deck()
>>> dealer.play_round()
>>> dealer.hand
[10, 8]
"""
while not self.busted and self.card_sum <= 16:
self.signal_hit(self)
if __name__ == "__main__":
import doctest
doctest.testmod()
Code Screenshots:

Source code for card_deck.py:
import random
class CardDeck:
class Card:
def __init__(self, value):
self.value = value
self.next = None
def __repr__(self):
return "{}".format(self.value)
def __init__(self):
self.top = None
def shuffle(self):
card_list = 4 * [x for x in range(2, 12)] + 12 * [10]
random.shuffle(card_list)
self.top = None
for card in card_list:
new_card = self.Card(card)
new_card.next = self.top
self.top = new_card
def __repr__(self):
curr = self.top
out = ""
card_list = []
while curr is not None:
card_list.append(str(curr.value))
curr = curr.next
return " ".join(card_list)
def draw(self):
"""
>>> import random; random.seed(1)
>>> deck = CardDeck()
>>> deck.shuffle()
>>> deck.draw()
10
>>> deck.draw()
8
>>> deck.draw()
10
>>> deck.draw()
6
>>> deck
8 9 3 10 2 10 6 5 8 10 3 10 9 2 10 9 6 10 5 5 2 6 8 7 2 4 10 4 11
10 3 10 10 5 7 10 10 11 7 7 3 11 10 4 4 9 11 10
"""
if self.top is not None:
node = self.top
self.top = self.top.next
return node.value
else:
return None
if __name__ == "__main__":
import doctest
doctest.testmod()
Code Screenshots:
Source code for blackjack_game.py:
from player import Player
from dealer import Dealer
class BlackjackGame:
def __init__(self, player_names):
self.dealer = Dealer()
self.player_list = [Player(name, self.dealer) for name in
player_names]
def play_rounds(self, num_rounds=1):
"""
>>> import random; random.seed(1)
>>> game = BlackjackGame(["Lawrence","Melissa"])
>>> print(game.play_rounds(2))
Round 1
Dealer: [10, 9] 0/0/0
Lawrence: [10, 6, 3] 0/1/0
Melissa: [8, 8] 0/0/1
Round 2
Dealer: [10, 10] 0/0/0
Lawrence: [10, 3] 0/1/1
Melissa: [9, 10] 0/0/2
"""
string = ""
for i in range(0, num_rounds):
self.dealer.hand = []
for p in self.player_list:
p.hand = []
self.dealer.shuffle_deck()
# deal first two cards
for _ in [1, 2]:
for p in self.player_list:
self.dealer.signal_hit(p)
self.dealer.signal_hit(self.dealer)
# play out round
for p in self.player_list:
p.play_round()
self.dealer.play_round()
# score round
if sum(self.dealer.hand[:2]) == 21:
for p in self.player_list:
if sum(p.hand[:2]) == 21:
p.record_tie()
else:
p.record_loss()
elif self.dealer.busted:
for p in self.player_list:
p.record_win()
else:
for p in self.player_list:
if sum(p.hand[:2]) == 21:
p.record_win()
elif p.busted or p.card_sum < self.dealer.card_sum:
p.record_loss()
elif p.card_sum > self.dealer.card_sum:
p.record_win()
elif p.card_sum == self.dealer.card_sum:
p.record_tie()
# build report
string += f"Round {i + 1}\n"
string += str(self.dealer) + "\n"
for p in self.player_list:
string += str(p) + "\n"
return string[0:-1]
def reset_game(self):
"""
>>> game = BlackjackGame(["Lawrence", "Melissa"])
>>> _ = game.play_rounds()
>>> game.reset_game()
>>> game.player_list[0]
Lawrence: [] 0/0/0
>>> game.player_list[1]
Melissa: [] 0/0/0
"""
self.dealer = Dealer()
self.player_list = [Player(p.name, self.dealer) for p in
self.player_list]
if __name__ == "__main__":
import doctest
doctest.testmod()
Code Screenshots:


Output Screenshots:
![? player = Player (None, None) > player.deal_to (11) player.hand [11] > player.deal_to (10) > player.hand [11, 10] player = P](http://img.homeworklib.com/questions/13a91c80-9bac-11eb-9660-2ddb867b7dda.png?x-oss-process=image/resize,w_560)

Hope it helps, if you like the answer give it thumbs up. Thank you.
Player Class Represents a participant in the game of blackjack. Must meet the following requirements: Stores...
Create a simplified Blackjack game using the Deck and Card classes (download the attached files to start). There is also a "TestCard" class that creates a Deck and runs some simple code. You may choose to use this file to help you get started with your game program. 1) Deal 2 cards to the "player" and 2 cards to the "dealer". Print both the player's cards, print one of the dealer's cards. Print the total value of the player's hand. 2) Ask...
Using C++ Create a Blackjack program with the following features: Single player game against the dealer. Numbered cards count as the number they represent (example: 2 of any suit counts as 2) except the Aces which can count as either 1 or 11, at the discretion of the player holding the card. Face cards count as 10. Player starts with $500. Player places bet before being dealt a card in a new game. New game: Deal 2 cards to each...
Must be in C++ Question: Blackjack (twenty-one) is a casino game played with cards. The goal of the game to draw cards that total as close to 21 points as possible without going over. All face cards count as 10 points, aces count as 1 or 11, and all other cards count their numeric value. The game is played against a dealer. The player tries to get closer to 21 (without going over) than the dealer. If the dealer busts...
For this assignment you will create a one-player variation of the game BlackJack. The game will be divided into five rounds. The goal of each round is to accumulate a hand of cards that gets as close to 21 without going over. At the beginng of the game you will start with a score of 100 points. After each round, the difference between your hand and 21 will be subtracted from your total score. The object of the entire game...
Need a blackjack code for my assignment its due in 3 hours: it has to include classes and object C++. Create a fully functioning Blackjack game in three separate phases. A text based version with no graphics, a text based object oriented version and lastly an object oriented 2D graphical version. Credits (money) is kept track of throughout the game by placing a number next to the player name. Everything shown to the user will be in plain text. No...
"Blackjack 40" my teacher created this assignment and I need help. He is using c++ and has provided this template: Further instructions are below the template! #include <iostream> #include <cmath> #include <cstdlib> using namespace std; //Will return a number from 1 to 13, representing the face of a card int draw_card() { return rand() % 13 + 1; } int main() { const int BET = 10; //This will allow you to control chance, to make testing easier cout <<...
Please write the program in python: 3. Design and implement a simulation of the game of volleyball. Normal volleyball is played like racquetball, in that a team can only score points when it is serving. Games are played to 15, but must be won by at least two points. 7. Craps is a dice game played at many casinos. A player rolls a pair of normal six-sided dice. If the initial roll is 2, 3, or 12, the player loses....
ill thumb up do your best
python3
import random
class CardDeck:
class Card:
def __init__(self, value):
self.value = value
self.next = None
def __repr__(self):
return "{}".format(self.value)
def __init__(self):
self.top = None
def shuffle(self):
card_list = 4 * [x for x in range(2, 12)] + 12 * [10]
random.shuffle(card_list)
self.top = None
for card in card_list:
new_card = self.Card(card)
new_card.next = self.top
self.top = new_card
def __repr__(self):
curr = self.top
out = ""
card_list = []
while curr is not None:...
Java BlackJack Game:
Help with 1-4 using the provided code below
Source code for Project3.java:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class Project3 extends JFrame implements ActionListener
{
private static int winxpos = 0, winypos = 0; // place window
here
private JButton exitButton, hitButton, stayButton, dealButton,
newGameButton;
private CardList theDeck = null;
private JPanel northPanel;
private MyPanel centerPanel;
private static JFrame myFrame = null;
private CardList playerHand = new CardList(0);
private CardList dealerHand = new CardList(0);...
You will write a two-class Java program that implements the Game of 21. This is a fairly simple game where a player plays against a “dealer”. The player will receive two and optionally three numbers. Each number is randomly generated in the range 1 to 11 inclusive (in notation: [1,11]). The player’s score is the sum of these numbers. The dealer will receive two random numbers, also in [1,11]. The player wins if its score is greater than the dealer’s...