Project 2 - Blackjack Due 7/1/12 by Midnight

Similar documents
DELIVERABLES. This assignment is worth 50 points and is due on the crashwhite.polytechnic.org server at 23:59:59 on the date given in class.

Make better decisions. Learn the rules of the game before you play.

PROBLEM SET 2 Due: Friday, September 28. Reading: CLRS Chapter 5 & Appendix C; CLR Sections 6.1, 6.2, 6.3, & 6.6;

For this assignment, your job is to create a program that plays (a simplified version of) blackjack. Name your program blackjack.py.

CSCI 4150 Introduction to Artificial Intelligence, Fall 2004 Assignment 7 (135 points), out Monday November 22, due Thursday December 9

A. Rules of blackjack, representations, and playing blackjack

CS 210 Fundamentals of Programming I Fall 2015 Programming Project 8

COMP 9 Lab 3: Blackjack revisited

CS 210 Fundamentals of Programming I Spring 2015 Programming Assignment 8

LET S PLAY PONTOON. Pontoon also offers many unique payouts as well as a Super Bonus of up to $5000 on certain hands.

Problem Set 4: Video Poker

CS Programming Project 1

CS Project 1 Fall 2017

AP Computer Science Project 22 - Cards Name: Dr. Paul L. Bailey Monday, November 2, 2017

A Case Study. Overview. References. Video poker Poker.Card & Poker.Hand General.dll & game variants

Lecture 14: Modular Programming

Live Casino game rules. 1. Live Baccarat. 2. Live Blackjack. 3. Casino Hold'em. 4. Generic Rulette. 5. Three card Poker

Players try to obtain a hand whose total value is greater than that of the house, without going over 21.

BRIDGE is a card game for four players, who sit down at a

After receiving his initial two cards, the player has four standard options: he can "Hit," "Stand," "Double Down," or "Split a pair.

Activity 1: Play comparison games involving fractions, decimals and/or integers.

Begin this assignment by first creating a new Java Project called Assignment 5.There is only one part to this assignment.

ProgrammingAssignment #7: Let s Play Blackjack!

Web-CAT submission URL: CAT.woa/wa/assignments/eclipse

Cashback Blackjack TO PLAY THE GAME. The objective of the game is to get closer to 21 than the dealer without going over.

CSE231 Spring Updated 04/09/2019 Project 10: Basra - A Fishing Card Game

Venn Diagram Problems

CS107L Handout 06 Autumn 2007 November 2, 2007 CS107L Assignment: Blackjack

User Guide / Rules (v1.6)

HOW TO PLAY BLACKJACK

Name: Checked: Answer: jack queen king ace

CS 152 Computer Programming Fundamentals Lab 8: Klondike Solitaire

10 Game. Chapter. The PV Unit comes with two built-in games for your enjoyment. The games are named Game-1 and Game-2.

Name: Checked: jack queen king ace

Bridge Players: 4 Type: Trick-Taking Card rank: A K Q J Suit rank: NT (No Trumps) > (Spades) > (Hearts) > (Diamonds) > (Clubs)

CSEP 573 Applications of Artificial Intelligence Winter 2011 Assignment 3 Due: Wednesday February 16, 6:30PM

3. If you can t make the sum with your cards, you must draw one card. 4. Players take turns rolling and discarding cards.

how TO PLAY blackjack

To play the game player has to place a bet on the ANTE bet (initial bet). Optionally player can also place a BONUS bet.

BLACKJACK. Game Rules. Definitions Mode of Play How to Play Settlement Irregularities

PLAYERS AGES MINS.

AP Computer Science A Practice Test 6 - Picture and Elevens Labs

CS101 - Object Construction and User Interface Programming Lecture 10

NUMB3RS Activity: A Bit of Basic Blackjack. Episode: Double Down

Corners! How To Play - a Comprehensive Guide. Written by Peter V. Costescu RPClasses.com

FreeCell Puzzle Protocol Document

The game of poker. Gambling and probability. Poker probability: royal flush. Poker probability: four of a kind

BLACKJACK Perhaps the most popular casino table game is Blackjack.

HOW to PLAY TABLE GAMES

Blackjack OOA, OOD, AND OOP IN PYTHON. Object Oriented Programming (Samy Zafrany)

Battle. Table of Contents. James W. Gray Introduction

LEARN HOW TO PLAY MINI-BRIDGE

2 The Universe Teachpack: Client/Server Interactions

ECE2049: Foundations of Embedded Systems Lab Exercise #1 C Term 2018 Implementing a Black Jack game

A UNIQUE COMBINATION OF CHANCE & SKILL.

To use one-dimensional arrays and implement a collection class.

Poker Rules Friday Night Poker Club

Programming Assignment 4

BEGINNING BRIDGE Lesson 1

All Blackjack HOUSE RULES and dealing procedures apply. Dealer will offer insurance when showing an ACE.

LESSON 3. Responses to 1NT Opening Bids. General Concepts. General Introduction. Group Activities. Sample Deals

Welcome to the Best of Poker Help File.

POINTS TO REMEMBER Planning when to draw trumps

Blackjack Project. Due Wednesday, Dec. 6

Buster Blackjack. BGC ID: GEGA (October 2011)

Table Games Rules. MargaritavilleBossierCity.com FIN CITY GAMBLING PROBLEM? CALL

Conditional Probability Worksheet

TABLE GAMES RULES OF THE GAME

Here are two situations involving chance:

UNIT 9B Randomness in Computa5on: Games with Random Numbers Principles of Compu5ng, Carnegie Mellon University - CORTINA

Up & Down GOAL OF THE GAME UP&DOWN CARD A GAME BY JENS MERKL & JEAN-CLAUDE PELLIN ART BY CAMILLE CHAUSSY

SPANISH 21. Soft total-- shall mean the total point count of a hand which contains an ace that is counted as 11 in value.

LESSON 4. Eliminating Losers Ruffing and Discarding. General Concepts. General Introduction. Group Activities. Sample Deals

No Flop No Table Limit. Number of

Chapter 5: Probability: What are the Chances? Section 5.2 Probability Rules

Presents: Basic Card Play in Bridge

LESSON 3. Developing Tricks the Finesse. General Concepts. General Information. Group Activities. Sample Deals

Activity 6: Playing Elevens

Counting integral solutions

3 The multiplication rule/miscellaneous counting problems

Bridge Tutor 1. lad1elhaek A DIVISION OF TANDY CORPORATION FORT WORTH, TEXAS 76102

Content Page. Odds about Card Distribution P Strategies in defending

Poker Hands. Christopher Hayes

A Rule-Based Learning Poker Player

Acing Math (One Deck At A Time!): A Collection of Math Games. Table of Contents

Chapter 2 Integers. Math 20 Activity Packet Page 1

Conditional Probability Worksheet

Texas Hold em Poker Basic Rules & Strategy

18.S34 (FALL, 2007) PROBLEMS ON PROBABILITY

CSE 231 Fall 2012 Programming Project 8

CS188: Artificial Intelligence, Fall 2011 Written 2: Games and MDP s

CARIBBEAN. The Rules

Maryland State Lottery and Gaming Control Agency Standard Rules - Double Draw Poker

13:69E 1.13Z 5 Card Hi Lo table; physical characteristics. (a) 5 card hi lo shall be played at a table having on one side

LESSON 2. Objectives. General Concepts. General Introduction. Group Activities. Sample Deals

THE NUMBER WAR GAMES

CATFISH BEND CASINOS RULES OF THE GAME THREE CARD POKER

1. Definitions 2. Mode of Play 3. How to Play 4. Settlement 5. Irregularities

HEADS UP HOLD EM. "Cover card" - means a yellow or green plastic card used during the cut process and then to conceal the bottom card of the deck.

Developed by Rashmi Kathuria. She can be reached at

Transcription:

Project 2 - Blackjack Due 7//2 by Midnight In this project we will be writing a program to play blackjack (or 2). For those of you who are unfamiliar with the game, Blackjack is a card game where each card has a value: Numbered cards have the same values as their numbers Jacks, Queens, and Kings have a value of 0 Aces have a value of or In our game we will have two players the user and the dealer. To start each hand the user and dealer are dealt an initial two card hand with the option of drawing cards to bring the total value to 2 or less without exceeding it, so that the dealer will lose by having a lesser hand than the player or by exceeding 2. In each hand the game proceeds as follows: ) The deck is shuffled. 2) The user and dealer are dealt 2 cards each -- so that the first card goes to the user, the second to the dealer, the third to the user, and the fourth to the dealer (the dealers fourth card will be hidden -- so only print out the first card). 3) Give the user the choice to hit (draw a card) or stand (end their turn). 4) Repeat 3) until the user chooses to stand or until they bust (go over 2). 5) If the user busts the hand is over and the dealer wins. 6) If the user doesn t bust the dealer continues to draw cards until she busts or her hand exceeds 7. 7) The player with the greatest hand, not exceeding 2, wins. The Classes: To complete this project you must write 4 classes: ) Card - this class will represent individual cards 2) Deck - this class will represent the entire deck 3) Player - this class will represent both the user and dealer 4) Blackjack - this class will hold the main function, and will control the flow of the game The following gives the specs (data, and methods) for each of the four classes -- feel free to add other data/methods to your classes, the specs below define the minimum.

The Card Class: public class Card { private int num; // num will represent the number on the card or // the face. // = Ace // 2 = 2 // 3 = 3 // // 0 = 0 // = Jack // 2 = Queen // 3 = King private char suit; // suit will be one of 4 letters: // C for clubs, // H for hearts, // D for diamonds, // or S for spades // Constructor public Card(int num, char suit) { // Initialize the private data with the parameters passed in public boolean isace() { // Return true if num == false otherwise public int getvalue() { // Returns the blackjack value of the card // if the card is 2 thru 0 return num // if the card is a Jack, Queen or King return 0 // if the card is an Ace return public String tostring() { // Return the card as a string. For example, if the card was a // king of diamonds return KD

The Deck Class: import java.util.random; // Import Random to help shuffle the deck public class Deck { private Card[] deck; // Array of cards to store all 52 cards private int nextcard; // Index of the next card to be dealt // Constructor public Deck() { // Set deck to a new Card array of size 52 // Set nextcard to 0 // Call initializedeck private void initializedeck() { // Note that this is a private function // Create all 52 cards and add them to the deck // Hint: use a nested for-loop (a for-loop inside a for-loop) public void shuffledeck() { // Shuffle the deck: // Create a new random number generator // Randomly select two indexes and swap the // cards at these two indexes do this a // thousand times and the deck should be // well shuffled. // Also set nextcard back to 0 public Card nextcard() { // Return the next card in the deck // Don't forget to increment nextcard

The Player Class public class Player { private Card[] hand; // Array of cards to hold the players hand private int emptyindex; // Holds the index of the next empty // index in the hand private int numaces; // Holds the number of aces // Constructor public Player() { // Set hand to a new card array large enough // hold any blackjack hand -- 20 should do it // Set emptyindex to 0 // Set numaces to 0 public void addcard(card card) { // Add the card to the hand (at the emptyindex index) // Don't forget to increment emptyindex // If the card is an ace increment numaces public Card firstcard() { return hand[0]; // this is used to display // the dealers initial hand // this method is complete public int getvalue() { // Return the blackjack value of the hand: // Create a sum variable and initialize it to 0 // Loop though your hand and for each // card call getvalue() and add that to sum // Remember that an ace can be either a or, // but when the getvalue() function only // returns an for an ace. So if your sum // is greater than 2, then start turning your // aces into 's instead of 's. That is, // create a while loop that sets sum // to sum - 0, continue doing this until sum // is less than 22 or you run out of aces.

// Hint - you shouldn't loop through the entire // hand array -- much of the hand array will // be empty indexes public String tostring() { // Return hand as a string -- the string should show // each card in your hand followed by a space (use the cards tostring). // Then append the total blackjack value to the string // use getvalue()

The Blackjack Class: import java.util.scanner; //Import Scanner for user input public class Blackjack { public static void main(string[] args) { // The main method controls the basic flow of the game // First create a Scanner object to get user input // Create an instance of the deck class // Print a welcome message to the user // Then code the following steps: // ) Create two instances of the player class // one for the user and one for the dealer. // 2) Shuffle the deck // 3) Print the main menu: // "Please choose from the following" // ") Start Game" // "" // 4) Get user input -- if it's 2 display a // message and end the program (use break) // 5) Deal the hands (two cards to the user // two to the dealer) // 6) Show the dealers first card // 7) Show the users hand -- use tostring // 8) Display hit/stand menu to user // "Please choose from the following:" // " ) Hit // " // 9) Get the users input // if it's a, then deal the user another card // 0) Repeat steps 7 to 9 until the user enters a 2 or // the user busts (goes over 2). // ) If the user busts, print a message

// "Sorry you lose" and go back to step ) // 2) Continue dealing the dealer cards until // her hand is greater than or equal to 7 // 3) Print the dealers hand -- use tostring // 4) Determine the winner // if the dealer busted, the user wins // if the dealers hand is greater than the user, the dealer wins // if the two hands are equal they push // else the dealer wins // 5) Display the winner, and go back to step

Sample Output: Welcome to the CS 52 Blackjack Table ) Start Game The dealer is showing: 3C 2C 8C, Total = 0 ) Hit 2C 8C 9C, Total = 9 ) Hit 2 The dealer has: 3C 6H AS, Total = 20 Sorry you lose ) Start Game The dealer is showing: 6S AH 4H, Total = 5 ) Hit AH 4H QS, Total = 5 ) Hit

AH 4H QS 8S, Total = 23 Sorry you bust ) Start Game The dealer is showing: 3C QC 5C, Total = 5 ) Hit 2 The dealer has: 3C AC 2H 7D 4C, Total = 7 Sorry you lose ) Start Game The dealer is showing: 9H 7S 5D, Total = 2 ) Hit 7S 5D AH, Total = 3 ) Hit 7S 5D AH 4H, Total = 7 ) Hit 2 The dealer has: 9H 7D 0H, Total = 26

Dealer busts -- You WIN!!! ) Start Game The dealer is showing: 8C 4D 3C, Total = 7 ) Hit 4D 3C 6C, Total = 3 ) Hit 4D 3C 6C AD, Total = 4 ) Hit 4D 3C 6C AD KD, Total = 24 Sorry you bust ) Start Game The dealer is showing: 8D 4H QC, Total = 4 ) Hit 4H QC 8H, Total = 22 Sorry you bust

) Start Game The dealer is showing: 5S 4C 9S, Total = 3 ) Hit 4C 9S 5C, Total = 8 ) Hit 2 The dealer has: 5S AC KC 6S, Total = 22 Dealer busts -- You WIN!!! ) Start Game The dealer is showing: 4H 7S 9C, Total = 6 ) Hit 2 The dealer has: 4H 5S 8D, Total = 7 Sorry you lose ) Start Game The dealer is showing: 9S

4H 3D, Total = 7 ) Hit 4H 3D 6D, Total = 3 ) Hit 4H 3D 6D 9C, Total = 22 Sorry you bust ) Start Game The dealer is showing: 0H 2S 2D, Total = 4 ) Hit 2S 2D QD, Total = 4 ) Hit 2S 2D QD AD, Total = 5 ) Hit 2S 2D QD AD 6S, Total = 2 The dealer has: 0H 9D, Total = 9 You WIN!!!!

) Start Game 2 Thanks for playing