CS 210 Fundamentals of Programming I Spring 2015 Programming Assignment 8

Similar documents
CS 210 Fundamentals of Programming I Fall 2015 Programming Project 8

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

CS Project 1 Fall 2017

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

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

A. Rules of blackjack, representations, and playing blackjack

COMP 9 Lab 3: Blackjack revisited

Poker Rules Friday Night Poker Club

CS Programming Project 1

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

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

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

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

Blackjack Project. Due Wednesday, Dec. 6

HOW TO PLAY BLACKJACK

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

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

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

Buster Blackjack. BGC ID: GEGA (October 2011)

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

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

2. A separate designated betting area at each betting position for the placement of the ante wager;

HIGH CARD FLUSH 1. Definitions

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

TABLE GAMES RULES OF THE GAME

LESSON 8. Putting It All Together. General Concepts. General Introduction. Group Activities. Sample Deals

LEARN HOW TO PLAY MINI-BRIDGE

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

how TO PLAY blackjack

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

The student will explain and evaluate the financial impact and consequences of gambling.

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

CARIBBEAN. The Rules

HOW to PLAY TABLE GAMES

GAMBLING ( ) Name: Partners: everyone else in the class

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

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

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

Venn Diagram Problems

Electronic Wireless Texas Hold em. Owner s Manual and Game Instructions #64260

Here are two situations involving chance:

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

A UNIQUE COMBINATION OF CHANCE & SKILL.

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

No Flop No Table Limit. Number of

(e) Each 3 Card Blitz table shall have a drop box and a tip box attached to it on the same side of the table as, but on opposite sides of the dealer.

LESSON 3. Third-Hand Play. General Concepts. General Introduction. Group Activities. Sample Deals

A Rule-Based Learning Poker Player

Ante or ante wager means the initial wager required to be made prior to any cards being dealt in order to participate in the round of play.

ELKS TOWER CASINO and LOUNGE. EZ BACCARAT Panda 8

CHAPTER 69F RULES OF THE GAMES

Problem Set 4: Video Poker

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

Activity 6: Playing Elevens

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

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

TABLE OF CONTENTS TEXAS HOLD EM... 1 OMAHA... 2 PINEAPPLE HOLD EM... 2 BETTING...2 SEVEN CARD STUD... 3

Lab 1. CS 5233 Fall 2007 assigned August 22, 2007 Tom Bylander, Instructor due midnight, Sept. 26, 2007

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.

Lab Exercise #10. Assignment Overview

LESSON 2. Developing Tricks Promotion and Length. General Concepts. General Introduction. Group Activities. Sample Deals

Chapter 2 Integers. Math 20 Activity Packet Page 1

CPSC 217 Assignment 3

Texas Hold em Poker Basic Rules & Strategy

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

LESSON 5. Rebids by Opener. General Concepts. General Introduction. Group Activities. Sample Deals

FOUR CARD POKER. Hand-- means the best four card poker hand that can be formed by each player and the dealer from the cards they are dealt.

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

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

Programming Assignment 4

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

Texas Hold'em $2 - $4

11/3/71 BASIC (VI) basic -- DEC supplied BASIC

FLOP POKER. Rank-- or ranking means the relative position of a card or hand as set forth in Section 5.

BLACKJACK Perhaps the most popular casino table game is Blackjack.

LESSON 5. Watching Out for Entries. General Concepts. General Introduction. Group Activities. Sample Deals

BLACKJACK. The following words and terms, when used in this section, shall have the following meanings unless the context clearly indicates otherwise.

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

Programming Exam. 10% of course grade

STATION 1: ROULETTE. Name of Guesser Tally of Wins Tally of Losses # of Wins #1 #2

Blazing 7 s Blackjack Progressive

13:69E-1.13Z Criss cross poker; physical characteristics

PHASE 10 CARD GAME Copyright 1982 by Kenneth R. Johnson

Welcome to the Best of Poker Help File.

Lesson 3. Takeout Doubles and Advances

Crown Melbourne Limited. Blackjack Rules

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

Maryland State Lottery and Gaming Control Agency Standard Rules Criss Cross Poker

LESSON 6. Rebids by Responder. General Concepts. General Introduction. Group Activities. Sample Deals

LET IT RIDE POKER. Stub-- means the remaining portion of the deck after all cards in the round of play have been dealt or delivered.

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

The Exciting World of Bridge

PLAYERS AGES MINS.

CPSC 217 Assignment 3 Due Date: Friday March 30, 2018 at 11:59pm

Martin J. Silverthorne. SILVERTHORNE PuBLICATIONS

THE NUMBER WAR GAMES

Blackjack and Probability

Lesson 2. Overcalls and Advances

Bonus Side Bets Analysis

Math-Essentials. Lesson 9-2: Counting Combinations

Transcription:

CS 210 Fundamentals of Programming I Spring 2015 Programming Assignment 8 40 points Out: April 15/16, 2015 Due: April 27/28, 2015 (Monday/Tuesday, last day of class) Problem Statement Many people like to visit casinos for entertainment. One of the common games available is Blackjack. In order to increase our chances of winning, we would like a program to help us practice playing the game. Blackjack Game You are encouraged to look at the Wikipedia entry for a fuller description of the game. Here are the essentials: Blackjack is played with cards having four suits, Spades, Hearts, Diamonds, and Clubs, each with 13 possible values, Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, and King. A blackjack hand starts with two cards. The game points of the cards are 10 for face cards (Jack, Queen, King), 1 or 11 for Aces, and the number of all the rest of the cards (e.g., 2 for Two). The goal is to try to get a total as close to 21 as possible without going over. Note: since Aces can be either 1 or 11, you pick the largest value which doesn t exceed 21, if possible. The only options you have are to either hit, which means to add another card to your hand, or to stand which ends your turn. You are playing against the dealer. At the beginning of the game, you only get to see one of the dealer s cards. After you are done playing, the dealer reveals the second card and plays his turn. The dealer must follow this rule: If the total is less than 17, he must hit, otherwise, he must stand. If you go over 21, you lose. Otherwise, if the dealer goes over 21, you win. Otherwise, the person with the larger total wins. If the totals are the same it s a tie. Blackjack is a gambling game, so before each hand you make a bet. If you win, you get the double the amount of your bet back. If you lose, you get nothing. If there s a tie, you get your original bet back, but with no extra. Program Description The sample run shows a typical interaction with this program. Since there is a random element to this game, the submission system actually will be checking your implementation of the card playing library. The instructor will check your actual game by hand. In our program, the user will start with $1,000. The game will end either when the player runs out of money, or signifies that they are done playing by placing a negative bet. Also, typical casino blackjack games use multiple decks of cards (called a shoe) to make it more difficult to count cards. At the beginning of the program, the user is asked how many decks they wish to play with. This program will allow up to 10 decks to be used. Program Design This program is required to use several different structs to represent the different data types in this program, along with functions that perform operations on them. These functions are what the submission system will test. 04/15/2015 Page 1 of 6 D. Hwang

Cards Cards are represented by a structure named card_t. It must have two fields representing the suit (a character) and the value of the card (an integer). Card Functions create_card This function receives a suit character and an a card value, and returns a card_t struct. It should accept upper or lowercase for the suit and convert lowercase to uppercase (using toupper()). If the suit character is not one of 'S' (for Spades), 'H' (for Hearts), 'D' (for Diamonds), or 'C' (for Clubs), the function should set the suit field to 'C'. The card value must be 1 (for Ace), 2 (for Two), etc., up to 13 (for King). If the card value is not 1 13, the function should set the card value field to 2. (Thus the default card value is the Two of Clubs.) print_card This function receives a single card and prints out a long description of it on a single line. (e.g. "Ace of Hearts", "7 of Diamonds") with no trailing newline. points This function receives a single card and returns the Blackjack game points for this card. Since Aces can be either 1 or 11, this function will return 1. The logic for computing the score of an entire hand will take the 11 case into account. Shoe The shoe is deck of all the cards. It will be represented by a structure named shoe_t. It will have 3 fields. The first field is a dynamic array of card_t's. It must be allocated exactly large enough to hold all of the cards. The second field is an integer that represents the total number of 52 card decks that make up the full shoe. The third field is an integer to keep track of the next card that will be dealt out of the shoe. The easiest way to do this is to not actually remove the card from the array, but move this index to the next card that will be dealt. Shoe Functions create_shoe This function receives an integer that is the number of decks in the shoe and returns a shoe that is completely initialized with all the cards and shuffled. draw_card This function receives and passes back a shoe, draws the next card from it and returns it. The shoe must be passed back, since the act of drawing a card must change the next card field. Note, if there are no cards left to draw, reshuffle the deck, and draw the first card of the shoe. cards_left This function receives a shoe and returns the number of cards that are left to be dealt from it before it must be reshuffled. reshuffle This function receives and passes back a shoe and randomizes the cards within it and resets the next card field. It should print out SHUFFLING, so the card counters will know that everything is reset. To shuffle an array, you have to swap each element with a random element. You can use the following pseudocode to shuffle an array with n elements: for(i=0; i<n; i++) { random_position = i + rand()%(n-i); swap arr[i] with arr[random_position] } One other wrinkle with this is that the random number generator will always generate the same sequence unless you seed it. The code to do this is: srand(time(0)); You will need to include <time.h> for this to work. 04/15/2015 Page 2 of 6 D. Hwang

free_shoe This function receives and passes back a shoe and frees the dynamic array within it. This will only need to be called at the end of your program. Hand The hand is all cards that a player (or dealer) currently has. It will represented by a structure named hand_t that has two fields. The first field is an array of card_t cards that are the actual cards. Since there can never be more than 21 cards in a legal blackjack hand, we don t need to use dynamic arrays, we can simply set the maximum size to 21. The second field is an integer representing the number of cards actually in the array. By combining these two fields into a single struct, we won t have to constantly pass two arguments around. Hand Functions empty_hand This function returns an empty hand (simply has the number of cards set to 0). This is useful when initializing variables. print_hand This function receives a hand and prints each card in the hand on a separate line. add_card_to_hand This function has two parameters. The first parameter is the hand to add a card to that is received and passed back. It must be by passed back because we are actually changing its internal values. The second parameter is the card_t card that will be added to the hand. blackjack_points This function receives a hand and returns an integer that is the blackjack point value of the hand. Since Aces can be a bit tricky, here s a hint: start off counting them as 1 point, then if, there's an Ace and the total is less than 11, add 10 points. Note that only one Ace will ever be counted as 11 points. The Main Program Given all of the above functions, the main function is somewhat straightforward. Here is a rough outline of the game: 1. Print the greeting and initialize the player s stake to $1,000. 2. Prompt and get the number of decks that will be in the shoe for this game. (Make sure that only legal numbers are allowed) 3. While the player still has money and hasn t quit by entering a negative bet: (a) Print the remaining stake and the number of cards left in the shoe. (b) Ask the player for the bet (and validate it, i.e. less than or equal to the amount player currently has). (c) Draw the dealer s hand and player s hand. (d) Display only the first card of the dealer s hand and the entire player's hand (e) While the player s score is less than 21 and they haven t stood: i. Ask the user to stand or hit (and validate the input). (f) Determine the winner and update the player s stake. 4. Print the final results of the games. Coding Notes The names of the structs and functions and order of parameters just match exactly as given above, otherwise the submission system will not be able to compile the test program. The struct definitions and the function prototypes must be put in a file named (exactly) cards.h and the function definitions must be put in a file named (exactly) cards.c. Both cards.c and the main program file main.c will need to include the cards.h file. Recall that reference parameters are pointers to the actual argument. When using a pointer to a struct, to access a field use the "arrow" operator (->) instead of the "dot" operator. 04/15/2015 Page 3 of 6 D. Hwang

REMINDER: Your program must compile for it to be graded. Submissions that do not compile will be returned for resubmission and assessed a late penalty. Submissions that do not substantially work also will be returned for resubmission and assessed a late penalty. Follow the program documentation guidelines in the C Programming Style Guideline handout. As stated in the syllabus, part of the grade on a programming assignment depends on how well you adhere to the guidelines. The grader will look at your code and grade it according to the guidelines. What to Submit Electronically submit a zipfile containing main.c, card.h, and card.c as explained in the handout Submission Instructions for CS 210. The submission system will start accepting assignments no earlier than the evening of Wednesday, April 22. Sample Runs (user input shown in bold) Welcome to Blackjack! How many decks do you wish to play with (1-10)? 1 SHUFFLING! Your stake: $1000 Cards left in the shoe: 52 Enter your bet (negative to quit): 1000 The Dealer is showing 3 of Hearts 6 of Spades 3 of Clubs Score = 9 6 of Spades 3 of Clubs 7 of Hearts Score = 16 Do you want to (H)it or (S)tand? s Dealer cards: 3 of Hearts 8 of Diamonds 9 of Diamonds Dealer wins with a score of 20. You Lost! You ve lost your entire stake! Welcome to Blackjack! How many decks do you wish to play with (1-10)? 2 SHUFFLING! Your stake: $1000 04/15/2015 Page 4 of 6 D. Hwang

Cards left in the shoe: 104 Enter your bet (negative to quit): 200 The Dealer is showing 5 of Hearts 10 of Hearts Ace of Clubs Score = 11 10 of Hearts Ace of Clubs 8 of Hearts Score = 19 Do you want to (H)it or (S)tand? s Dealer cards: 5 of Hearts 9 of Clubs Ace of Clubs 9 of Spades Dealer Busts. You Win $400! Your stake: $1200 Cards left in the shoe: 97 Enter your bet (negative to quit): 800 The Dealer is showing Jack of Spades 2 of Clubs King of Spades Score = 12 2 of Clubs King of Spades 2 of Diamonds Score = 14 2 of Clubs King of Spades 2 of Diamonds 9 of Diamonds Score = 23 You Busted. You Lose! Your stake: $400 Cards left in the shoe: 91 Enter your bet (negative to quit): 200 The Dealer is showing 4 of Diamonds 04/15/2015 Page 5 of 6 D. Hwang

Queen of Spades 10 of Spades Score = 20 Do you want to (H)it or (S)tand? s Dealer cards: 4 of Diamonds 9 of Diamonds Queen of Hearts Dealer Busts. You Win $400! Your stake: $600 Cards left in the shoe: 86 Enter your bet (negative to quit): -1 You ended the night with $600 04/15/2015 Page 6 of 6 D. Hwang