联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2020-11-05 11:27

TD 5 : Blackjack

Advanced Object Oriented Design Programming

NB : you have 2 weeks to complete this TD

WARNING: You are allowed to discuss with your peers BUT you are NOT ALLOWED to share your code.

This policy is strictly enforced with automated tools and each exam is checked individually.

Introduction

The purpose of this TD is to implement a blackjack game. Please follow https://en.wikipedia.org/wiki/Blackjack to get a hold of

the general rules. During the lab, please pay attention to the distribution of features into classes and data encapsulation.

D

1. The set of cards that each player receives and holds in his or her hands is also known as that player’s hand.

2. The undealt cards, if any, are left face down in the middle of the table, forming the stock (also called the talon, widow,

skat or kitty depending on the game and region).

The Cards

Write a Card class, which encapsulates a card, enclosing its value (2-10, jack, queen, king or ace) and suit (spades, hearts,

diamonds or clubs). The class must contain the following:

a constructor to initialize the value and suit of the card

getter methods to value and suit

an equals method, to check whether two cards are equal

a toString method for generating a representation as a String

Write a method main to test the methods that you just wrote.

Packets of cards: hands and stocks

Write SimpleHand and SimpleStock classes to represent the hand and the stock of a player, respectively.

Class SimpleStock must contain the following:

a constructor to create a new standard 52-card deck;

a isValid method, to check if the stock only contains cards from a standard deck of 52 cards and if all the cards are

different;

a isComplete method, to check if the stock is a complete set of 52 cards;

a method toString to generate a representation of the heel in String form.

Class SimpleHand must contain the following:

an isValid method, to check if the hand contains only cards from a standard deck of 52 cards and if all the cards are

different;

a value method, to calculate the value of a given hand;

a compareTo method to see if the current hand beats another given hand (see comparable );

a toString method to generate a representation of the hand as a String .

Write a method main to test the methods you just wrote. You can leverage Math.random() or Random().nextInt()

REFACTOR

Hand and Stocks have functions in common.

Reformat the code, in order to be compliant with OOP principles, for the classes Hand and Stock . What is the parent

concept of Hand and Stock ? A CardSet !

Look out for different constructors ( CardSet vs Hand vs Stock ).

Players and Games

Write two Game and Player classes.

Add a transferCards method to put a given number of cards from the stock to the hands of a player.

Please take some time to select the right place for where to put this method.

Write two HumanPlayer and ComputerPlayer subclasses. These two subclasses must contain a boolean pickCard() method,

that returns true if the player would like to have another card in his hand and false otherwise. For the human player choice,

ask the user.

The computer takes another card if and only if the total value of his hand is less than or equal to 16.

The human player chooses whether to pick up another card from the command line.

Use Scanner to read in from command line.

The Scanner needs to be closed at the end of the program. Find a way to access the scanner from outside the class and

close it at the end of the game.

Write a method main in the Game class to allow a user to play a game of Blackjack against the computer.

Question: Why do you always lose?

ANSWER: no shuffling.

Blending & Mixing

Add a method shuffle to the Stock class, that makes 7 repetition of the American blend, which can be described by GilbertShannon-Reeds

model.

An American blend of a pack of (n) cards proceeds as the following two steps:

1. The packet of cards is split into 2 subpackages by separating the (k) first cards from it, where (k) is drawn from a binomial

distribution with the parameters (n) and (p = 1 / 2);

2. the two packages are mixed by repeating the following process:

with probability (a/(a+b)), a card is removed from the first packet.

with probability (b / (a + b)), a card is removed from the second packet, where (a) is the number of cards remaining in

the first packet and (b) is the one remaining in the second packet, and then placing the removed card in a third packet

(that will be the packet resulting from the American blend).

retour au site web du cours


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp