Chapter 5 Black Jack.

Slides:



Advertisements
Similar presentations
Black Jack in Objective-C
Advertisements

500 for 2 Enjoy your favourite card game with only 2 players 500 for 2
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 7.9Arrays of Pointers Arrays can contain pointers For.
Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view class.
© Glenn Rowe AC Lab 2 A simple card game (twenty- one)
Classes and Objects. What is Design? The parts of the software including – what information each part holds – what things each part can do – how the various.
It’s All in the Cards Adding and Subtracting Integers
Lecture 10. Simplified roulette European roulette has numbers 0,1,…36. xD0s
12 Pontoon1May Pontoon program CE : Fundamental Programming Techniques.
Computer Science 313 – Advanced Programming Topics.
Chapter 14 Ancestor Tree. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Provide a case study example from problem.
Design Example. Requirements Make a program that simulates the game of blackjack For now, we ignore money/betting…. just simulate game play But… this.
Chapter 9 Calculator. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 9-2 Chapter Objectives Provide a case study example from problem statement.
Chapter 5 Black Jack. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 5-2 Chapter Objectives Provide a case study example from problem statement.
VOCABULARY  Deck or pack  Suit  Hearts  Clubs  Diamonds  Spades  Dealer  Shuffle  Pick up  Rank  Draw  Set  Joker  Jack 
Refreshing Your Skills for Chapter 10.  If you flip a coin, the probability that it lands with heads up is 1/2.  If you roll a standard die, the probability.
Scavenger Hunt! 1. Pass out Scavenger Hunt worksheets 2. Break into pairs 3. Every pair should stand by a different poster (write the letter, on the poster,
Inner and Anonymous Classes Though you are captive in the OO paradigm, you can use inner classes and anonymous classes to get around this constraint and.
Computer Science 111 Fundamentals of Programming I More Data Modeling.
EXIT NEXT Click one of the buttons below or press the enter key BACKTOPICSProbability Mayeen Uddin Khandaker Mayeen Uddin Khandaker Ph.D. Student Ph.D.
Guide to Programming with Python
15.3 Counting Methods: Combinations ©2002 by R. Villar All Rights Reserved.
Objects and Classes Continued Engineering 1D04, Teaching Session 10.
Draw 3 cards without replacement from a standard 52 card deck. What is the probability that: 1.They are all red ? 2.At least one is black ? 3.They are.
Week 8 : User-Defined Objects (Simple Blackjack Game)
StructureStructure. Outline Introduction Structure Definitions Initializing Structures Accessing Members of Structures Using Structures with Functions.
Combinations 0.4. Combinations: a selection of r objects from a group on n objects where the order is not important.
Quiz: Draw the unit circle: Include: (1)All “nice” angles in degrees (2) All “nice” angles in radians (3) The (x, y) pairs for each point on the unit circle.
Chapter 4 Linked Structures.
11.9: Solving Probability Problems by Using Combinations
Combinations Problems
BEGINNERS’ LESSONS Welcome
Lecture 11.
Discrete Optimization
11/7/16 Entry 173 – Objective I will review and continue developing my understanding of uniform probability models, including the complement of an event.
The Addition Rule.
Discrete Optimization
@NAMEOFEVENTORBRIDGECLUB
Lecture 10.
Multiplication Rule and Conditional Probability
Fundamentals of Programming I More Data Modeling
Chapter 10: Counting Methods
Probability of casino games
Chapter 17 Linked Lists.
Chapter 19 Binary Search Trees.
Chapter 4 Inheritance.
Chapter 1 Preliminaries.
Chapter 14 Graphs and Paths.
Chapter 10 Datapath Subsystems.
Permutations and Combinations
Chapter 20 Hash Tables.
Blackjack: Counting Hands and Counting Cards
Combination and Permutations Quiz!
Fundamentals of Programming I More Data Modeling
Outline Anatomy of a Class Encapsulation Anatomy of a Method
How to Play Real Estate Dough™
Task 2 Implementation help
The Facts to Be Explained
Section 12.2 Theoretical Probability
Section 12.2 Theoretical Probability
Introduction: Some Representative Problems
Homework Due Friday.
Circuit Characterization and Performance Estimation
Chapter 6 Dynamic Programming.
BY: Cesar, Jennifer, Adrianne & Allen
Section 12.2 Theoretical Probability
Chapter 2 Reference Types.
P(softball) = P(not a baseball) = P(golf ball) = A box contains 3 tennis balls, 7 softballs, and 11 baseballs. One ball is chosen at random. Find.
Chapter 4 Greedy Algorithms.
HOW TO PLAY POKER.
Presentation transcript:

Chapter 5 Black Jack

Chapter Objectives Provide a case study example from problem statement through implementation Demonstrate how a set can be used to solve a problem Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Black Jack Black Jack is a card game typically involving multiple players and a dealer Each card in a hand is awarded points based upon its face value Face cards are worth 10 points each Numeric cards are worth their face value Aces are worth either 1 or 11 points Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Black Jack The goal of the game is to be closer to 21 than the dealer without going over 21 Black Jack is usually played with a shoe of cards (a collection of seven decks) Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Black Jack For this case study, we define black jack as a one-player v.s. the dealer interactive card game We will also limit the game to a single deck of cards rather than a shoe The player begins the game by clicking a Deal button Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Black Jack The player and the dealer are then dealt two cards The player can see their own cards and one card of the dealer The player then has the choice to hit (take another card) or stay (accept this hand as final for this game) If the player busts (goes over 21) then the game is over Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Black Jack Once the player elects to stay, the dealer then chooses to hit or stay The dealer must hit on 16 or less and must stay otherwise An Ace is considered to be 1 point rather than 11 points if otherwise it would cause the player or dealer to bust Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Black Jack - Initial Design Our black jack game is made up of the components of the game, the function of the game, and the user interface The components include cards, deck, and the hand of each player (including the dealer) The function includes controlling the order of play, whether a player hits or stays, and the value of a players hand Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Black Jack - Initial Design In this case study, there is a clear distinction between the low-level components of the game and the game itself These low-level components (card, deck, hand) are also very well defined in terms of state and behavior Thus a bottom-up approach to this design problem makes sense Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Black Jack - Initial Design Bottom-up simply means that we will design the low-level components first and then work our way up to the driver Other approaches include top-down and re-use based design Keep in mind, these are simply frameworks not rigid models Thus we will often find ourselves mixing these approaches even on the same system Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Black Jack - the Card Class A Card object must represent: the suit of the card (heart, diamond, club, or spade), the value of the card (1 to 11), the face of the card (ace, king, queen, six, two, etc.), the image of the card A Card object must also provide a constructor and operations to: retrieve the suit, value, face, or image of the card, an operation to change the value of an ace from 11 to 1 Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Black Jack - the Deck Class A deck is an unordered collection of unique cards Thus a set is a perfect collection to represent a deck The Deck class must include the collection of Cards, a method to retrieve a random card from the deck Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Black Jack - the Deck Class We will also choose to instantiate a new deck at the beginning of each new game This eliminates the possibility of ever having an “empty” deck during a game Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Black Jack - the Hand Class A hand is a collection of unique cards that have been dealt to a player or the dealer A Hand object must keep track of: the cards in the hand, the count of the cards in the hand, the value of the hand A Hand object must also provide methods to: add a card to the hand, remove a card from the hand, return the value of the hand, provide a string representation of the hand Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Black Jack - the Hand Class A Hand object must also provide a method to determine if an ace is in the hand and needs to be reduced in value from 11 to 1 As with a Deck, a set seems a reasonable collection to represent a Hand since each of the cards in the Hand are unique and order does not matter Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Black Jack - the BlackJack Class Separating the function of the game from the user interface, we will have a BlackJack class to control the game and a BlackJackGUI class to provide the interface The BlackJack class must represent the hands of both players the deck Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Black Jack - the BlackJack Class This class must provide methods to: deal the initial cards, hit a particular player, return the value of a player’s hand, determine if a player has busted, determine the winner of the game The BlackJack class will use the Deck class to store the deck and the Hand class to represent each player Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

Black Jack - the BlackJackGUI Class The BlackJackGUI class will provide the user interface for our game This class will provide: a deal button, buttons for the player to hit or stay, a display of each player’s hand a display of the winner of the game Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

FIGURE 5.2 User interface design for BlackJack Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

BlackJack - the BlackJackDemo Class The BlackJackDemo class will serve as the driver for our system This class simply creates an instance of BlackJackGUI and calls its display method Copyright © 2005 Pearson Addison-Wesley. All rights reserved.

FIGURE 5.1 Blackjack class diagram Copyright © 2005 Pearson Addison-Wesley. All rights reserved.