Blackjack is a simple and popular card game. For this lab, you will implement a simplified version using C++.
This assignment reinforces key object-oriented programming concepts including dynamic memory management (new/delete), class design (especially the Rule of Three), and random number generation.
For this lab, you must implement the following simplified Blackjack rules:
Change the implementation completed in lab to use dynamic memory allocation
(new/delete). As discussed in the video/lecture this week, in addition to
the constructor you need the following functions:
delete on memory that wasn't allocated with new.
CardDeck a(10); CardDeck b = a; CardDeck c(20); c = b;
You must include a small block in main.cpp (after your initial shuffle test but before Blackjack starts) that tests your copy constructor and assignment operator using all four lines above.
It is possible and probably likely your program will compile and work as
intended otherwise but not get points in Part 1 of the rubric below without these lines. This is why the tests above are important, and it
will prepare you for real-world class design and prevents hidden bugs.
delete, then allocate a new deck
using new, and shuffle it again. This mimics how a dealer would re-shuffle a new deck when the shoe runs low
Deck before shuffle: 0 1 2 3 4 5 6 7 8 9 Deck after shuffle: 4 8 1 7 2 0 9 3 5 6
Hint: You can use the modulus (%) operator
to convert cards from 0-51 to 0-12, and you can use new/delete to ensure
a constructor runs or a destructor runs for your decks.
In a historical Dr. Plank style 140/302 students would be asked to complete TopCoder challenges to further hone their coding skills, after which a TA would provide their solution on a high level (no actual code usually). These were opportunities for students who wanted more practice and/or experience to do more than the "main" assignment.
Code up a client for the children's game known as "War" (among other names; see below). The game proceeds as follows:
Aces can be either high or low depending on personal preference in your implementation.
I played this with my Pop Pop (the common nickname for grandfathers in the Philadelphia area), which he learned as a very young boy growing up in southwest Germany as "Tod und Leben."
Part 1: 16 points +4 Basic program structure is correct - program commented well (2 pts) - clean program structure with correct file names and use of header guards (2 pts) +4 non-default constructor works as requested with a fall back value +4 member functions are correct (2 pts each) - getSize() - shuffle() +2 client prints cards pre-shuffle +2 client prints cards after shuffle Part 2: 10 points +2. Functional and working destructor that calls delete properly +4 Functional and working copy constructor that works if/when you pass by value to a function +4 Functional and working assignment operator that works when you set one CardDeck to another, e.g., CardDeck a; CardDeck b = a; Although we will review your code and these should be relatively straightforward, we highly recommend that you use them as described to remove any bugs prior to submission (even though its ** very ** similar to the code provided in class) Part 3: 12 points +1 Aces are always 11 +2 User of the client is provided with a clear hit/stand option +4 The Blackjack game works as it should. Refer to https://en.wikipedia.org/wiki/Blackjack for details. In short: Player always goes first. If they go over 21, they bust and the dealer wins no matter what Dealer must "hit" until they reach 17 or higher. If the dealer goes over 21, and the user doesn't, the player wins Otherwise, whoever has the higher number wins. For purposes of this lab you can chose to either track ties or assign any tie to the user, aka, user wins +2 correctly keeps track of how many times a player wins and the dealer wins in your game +1 asks if a user wants to continue after every game +2 fewer than 15 cards triggers a new deck allocation and shuffle in Part 3
To facilitate testing, you were previously asked to clone the course Github repository as follows:
git clone https://github.com/semrich/CS202-fall24.git cs202
For this assignment, update this clone by using the following:
git pull
We'll discuss this in class but note that your client must be named
main.cpp and compilable
using make. Unlike other assignments this term, you will get more credit for the structure of your
code and following instructions versus solving unit tests. Please refer to the final rubric for
details.
The command to create a single .tar is:
tar -cvf lab3.tar CardDeck.h CardDeck.cpp main.cppBecause this assignment is more focused on C++ syntax/class design vs. solving specific problems, and since we checked for a very similar win condition in Lab 1, most of the to-be posted rubric will be on specific syntax/code items vs. solving scripts in advance.
Note: Although submission will be faciliated by Canvas, we will compile and test on EECS lab machines!
If you develop your solution elsewhere please make sure it works on
the lab computers prior to the deadline.