We think you have liked this presentation. If you wish to download it, please recommend it to your friends in any social system. Share buttons are a little bit lower. Thank you!
Presentation is loading. Please wait.
Published byVictor Florey
Modified over 2 years ago
© Glenn Rowe AC Lab 2 A simple card game (twenty- one)
© Glenn Rowe The game of 21 (blackjack) Computer versus human Use standard pack of cards Deal 2 cards to each player one visible to both players the other hidden - visible only to one player Aim: get a score as near 21 as possible without going over Card values: Ace through 10 face value Jack, Queen or King worth 10 each
© Glenn Rowe The game of 21 (rules) Human has first turn decide whether to take one card or not if not, human stands on cards held (cannot take any more cards on future turns) Computer turn is similar Play continues until either: both players stand one player goes over 21 (goes bust)
© Glenn Rowe Classes Main classes: Card - a single card Pack - the pack of cards Player - computer or human TwentyOne - runs the game play
© Glenn Rowe Card class represent one card in the pack 2 main properties: rank (ace, 2, 3, …Jack, Queen, King) suit (spades, hearts, diamonds, clubs) Rank can be int ace == 1, Jack == 11, Queen == 12, King == 13 Suit is string Provide interface methods & ToString method
© Glenn Rowe Pack class stores cards not yet used in play must allow variable size Can use array of Cards e.g. Card **cards for a Java-type array in C++ or use one of other methods in C++ Methods: Initialize (set pack to full 52 cards) Shuffle DealCard
© Glenn Rowe Pack class - Initialize method Initialize card array - assign 52 cards to the array 00FE34D cards 00FE45700FE51900FE623[…] new Card* 'cards' is a pointer to an array of pointers, so initialize it with cards = new Card*;
© Glenn Rowe Pack class - Initialize method Initialize card array - assign 52 cards to the array 00FE34D cards 00FE45700FE51900FE623[…] new Card* Each pointer in the array must then be initialized to a new Card object. E.g. for Ace of Spades: cards = new Card("Spade", 1); [but use a loop for better efficiency!] Spade1
© Glenn Rowe Pack class - Initialize method Initialize card array - assign 52 cards to the array 00FE34D cards 00FE45700FE51900FE623[…] new Card* Can access a card's suit with code like this: string suit = card->getSuit(); Spade1
© Glenn Rowe Pack class - dealing cards Need to deal cards in random order Two possibilities: select a card at random from an ordered pack shuffle the pack and then deal cards in fixed order If we select cards at random: need to mark a dealt card so it isn't selected again when most of pack is dealt, need to generate a lot of random numbers to find undealt card Shuffling usually more efficient
© Glenn Rowe Pack class - Shuffle method Various possibilities for shuffling algorithm Easiest is probably: Pick 2 cards at random locations in the pack Swap them Repeat above steps several hundred times
© Glenn Rowe Pack class - DealCard method If we have shuffled the pack: Maintain a 'topOfPack' marker in Pack class records position of next card to be dealt To deal a card: retrieve cards[topOfPack] then decrement topOfPack Remember to test if topOfPack >= 0
© Glenn Rowe Player class Represents computer or human player Requires: 1 array for visible cards Single Card variable for hidden card or could also use an array to allow for game variants AddCard() method adds a card to either visible or hidden array CardsValue() method calculates total value of all held cards ToString() for printing player's details
© Glenn Rowe Player class - card array Use same method as in Pack class for array of cards use Card **visible Allow array size that is large enough to hold a reasonable selection of cards (say, 10) AddCard should add a Card to 'visible' array
© Glenn Rowe Player class - CardsValue( ) CardsValue() totals up value of all cards held (visible + hidden) Use interface methods from Card class to retrieve card's rank Calculate value for each card and produce sum
© Glenn Rowe TwentyOne class TwentyOne class manages game play Will need: One Pack object Two Player objects (one for human, one for computer) In constructor: initialize Pack and Players
© Glenn Rowe TwentyOne class - game play To start game: deal 2 cards to each player one hidden, one visible For human's turn: Ask if they want a card If so, deal one (add to visible array) If not, mark human as 'standing' so they cannot ask for any more cards on later turns
© Glenn Rowe TwentyOne class - game play Computer's turn: use your strategy to determine if computer takes a card e.g. if holding > 15, stand; otherwise take card or devise your own strategy If computer takes card, add to visible list If not, mark computer as 'standing'
© Glenn Rowe TwentyOne class - end of turn After each turn: check total of cards held for player if player has gone bust (> 21), game is over if player has exactly 21, they win After each pair of turns (human + computer): check if both players are 'standing' if so, game is over…calculate totals for both players player closest to 21 wins if scores equal, game is a draw
© Glenn Rowe Destructors, copy constructors, = operators For each class containing dynamic memory: write a destructor Optionally: provide a copy constructor for each class and an overloaded = operator Follow examples in lectures / notes Once you've done one, the rest should be much the same
© Glenn Rowe main( ) function main() should create a TwentyOne object Then offer user the option of playing as many games as they like (use a loop as in nim lab)
© Glenn Rowe Optional extras - double-valued ace In full rules, the ace can be worth either 1 or 11 Modify your program to allow this Creates possibility of a player being dealt a 'natural' 21 ace + 10-valued card
© Glenn Rowe Optional extras - scoring / betting Keep score (how many wins, losses and draws for each player) or… Introduce a simple betting system e.g. each player bets a certain amount at each turn in the game after each game, winner takes all or split the total amount 50/50 for a draw
© Glenn Rowe Optional extras - computer strategy Do a bit of research on web Find out statistics for when it's best to take an extra card and when to stand Incorporate these into your program
Activity 2 Activity 1 Index Student Activity 1:Questions to familiarise students with the deck/pack of cards Student Activity 2: Probability questions.
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.
12 Pontoon1May Pontoon program CE : Fundamental Programming Techniques.
25 seconds left….. 24 seconds left….. 23 seconds left…..
Whiteboardmaths.com © 2004 All rights reserved
We will resume in: 25 Minutes We will resume in: 24 Minutes.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 7.9Arrays of Pointers Arrays can contain pointers For.
Lecture 10. Simplified roulette European roulette has numbers 0,1,…36. https://www.youtube.com/watch?v=4OeYU3_ xD0s https://www.youtube.com/watch?v=4OeYU3_.
Jeopardy Topic 1Topic Q 1Q 6Q 11Q 16Q 21 Q 2Q 7Q 12Q 17Q 22 Q 3Q 8Q 13Q 18Q 23 Q 4Q 9Q 14Q 19Q 24 Q 5Q 10Q 15Q 20Q 25 Final Jeopardy.
2008 Pearson Education, Inc. All rights reserved Pointers and Pointer-Based Strings.
Probability: Mutually Exclusive Events 1. There are 3 red, 4 black and 5 blue cubes in a bag. A cube is selected at random. What is the probability of.
1 Chapter 10 - Structures, Unions, Bit Manipulations, and Enumerations Outline 10.1Introduction 10.2Structure Definitions 10.3Initializing Structures 10.4Accessing.
VOCABULARY Deck or pack Suit Hearts Clubs Diamonds Spades Dealer Shuffle Pick up Rank Draw Set Joker Jack
WEEK 1 You have 10 seconds to name…
Chapter 5 Black Jack. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 5-2 Chapter Objectives Provide a case study example from problem statement.
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
1 Probability In this chapter, we will study the topic of probability which is used in many different areas including insurance, science, marketing, and.
2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 10 - Structures, Unions, Bit Manipulations, and Enumerations Outline 10.1Introduction 10.2Structure.
Chance We will base on the frequency theory to study chances (or probability).
You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
BLACKJACK SHARKS: Aabida Mayet, Omar Bacerra, Eser Kaptan March 15, 2010.
Addition 1’s to
Week 8 : User-Defined Objects (Simple Blackjack Game)
1 Greg Wilson BA 4234 CSC407: Software Architecture Fall 2006 Refactoring.
Lecture 18 Dr. MUMTAZ AHMED MTH 161: Introduction To Statistics.
ET156 – Introduction to C Programming. Loop Review The statements within a while loop execute until the loop repetition condition becomes false and might.
Title Subtitle 1. A. B. C. C. * D. Click to try again! INCORRECT.
2000 Deitel & Associates, Inc. All rights reserved. Chapter 16 – Bits, Characters, Strings, and Structures Outline 16.1Introduction 16.2Structure Definitions.
Principles of Programming Chapter 7: Arrays In this chapter, you will learn about Introduction to Array Array declaration Array initialization Assigning.
Addition Facts = = =
Design Example. Requirements Make a program that simulates the game of blackjack For now, we ignore money/betting…. just simulate game play But… this.
ABC Technology Project Mrs. Kiddle. ABCs of Technology Word 1 Word 2 Word 3 Word 4 Word 5 Word 6 Word 7 Word 8 Word 9 Word 19 Word 20 Word 21 Word 22.
Activity 1: Where am I? Play in pairs Each player has a number line or bead string and a pack of number cards Each player takes turns to turn over a number.
A R R A Y ! for Multiplication!!. TIME TO CHECK-UP ON OUR LESSON’S STANDARDS! MAFS.3.OA Interpret products of whole numbers, eg. interpret 5x7 as.
Computer Science 313 – Advanced Programming Topics.
An Extra Point Quiz. Are You Smarter than a Pre-Calc Student is a game in which the first 10 questions the class is playing the game together to earn.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
StructuresStructures Systems Programming. Systems Programming: Structures 2 Systems Programming: 2 StructuresStructures Structures Structures Typedef.
Dealer Comm Hand Player makes Ante bet and optional Bonus bet. Five cards are dealt to each player from the shuffler. Five cards are dealt from the shuffler.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 10 Arrays and Tile Mapping Starting Out with Games & Graphics.
April 2009 BEATING BLACKJACK CARD COUNTING FEASIBILITY ANALYSIS THROUGH SIMULATION.
Intro to Probability & Games Section 3.1. The Classic Deck of 52 Playing Cards.
1 CSC 221: Introduction to Programming Fall 2011 List comprehensions & objects building strings & lists comprehensions conditional comprehensions example:
StructuresStructures Systems Programming. StructuresStructures Structures Structures Typedef Typedef Declarations Declarations Using Structures with Functions.
Programming in C Chapter 10 Structures and Unions.
1 / / / /. 2 (Object) (Object) –, 10 (Class) (Class) –, –, – (Variables) [ Data member Field Attribute](, ) – (Function) [ Member function Method Operation.
Lecture 10 Flow of Control: Loops (Part 2) COMP1681 / SE15 Introduction to Programming.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 24 Lists, Stacks,
Black Jack in Objective-C CS 355. Cards 52 cards in a standard poker deck –Each card has a suit heart spade diamond club –and a rank A, 2, 3, 4, 5, 6,
© 2017 SlidePlayer.com Inc. All rights reserved.