part1.cppShuffle: [n | s | u <seed>]:
If they enter n, no shuffling will take place.
Otherwise, we'll shuffle using a random number generator, which of course
needs to be seeded. If
they enter s then time(0) is used
as the seed, as in part
2 of lab 6. Otherwise, the user must've given
the u option followed by a number; this number is then
used as the seed.
for i from 0 up to 51 do Disclaimer: This is not a good enough shuffling algorithm for set j to rand() % 52 "real" applications. Some shuffled orders are swap the index i element of the deck with the index j element more likely than others.
| Sample runs: red text represents user input, brown text is explanatory and not part of the output | |||
~/$ ./p1 Shuffle: [n | s | u <seed>]: n 102 ← 100*1 + 2 ← 2♣ 103 ← 100*1 + 3 ← 3♣ 104 ← 100*1 + 4 ← 4♣ 105 ← 100*1 + 5 ← 5♣ ⋮ 410 ← 100*4 + 10 ←10♠ 411 ← 100*4 + 11 ← J♠ 412 ← 100*4 + 12 ← Q♠ 413 ← 100*4 + 13 ← K♠ 414 ← 100*4 + 14 ← A♠ |
~/$ ./p1 Shuffle: [n | s | u <seed>]: u 2019 107 ← 100*1 + 7 ← 7♣ 403 ← 100*4 + 3 ← 3♠ 203 ← 100*2 + 3 ← 3♦ 408 ← 100*4 + 8 ← 8♠ ⋮ 413 ← 100*4 + 13 ← K♠ 412 ← 100*4 + 12 ← Q♠ 407 ← 100*4 + 7 ← 7♠ 213 ← 100*2 + 13 ← K♦ 414 ← 100*4 + 14 ← A♠ |
~/$ ./p1 Shuffle: [n | s | u <seed>]: u 2018 310 ← 100*3 + 10 ←10♥ 410 ← 100*4 + 10 ←10♠ 313 ← 100*3 + 13 ← K♥ 411 ← 100*4 + 11 ← J♠ ⋮ 208 ← 100*2 + 8 ← 8♦ 308 ← 100*3 + 8 ← 8♥ 205 ← 100*2 + 5 ← 5♦ 111 ← 100*1 + 11 ← J♣ 302 ← 100*3 + 2 ← 2♥ |
~/$ ./p1 Shuffle: [n | s | u <seed>]: s 410 407 113 DIFFERENT 202 EVERY ⋮ TIME 114 YOU 413 RUN IT 205 208 103 |
part2.cpp
| Sample runs: red text represents user input, brown text is explanatory and not part of the output | |||
~/$ ./p2 Shuffle: [n | s | u <seed>]: n 2♣ 3♣ 4♣ 5♣ ⋮ 10♠ J♠ Q♠ K♠ A♠ |
~/$ ./p2 Shuffle: [n | s | u <seed>]: u 2019 7♣ 3♠ 3♦ 8♠ ⋮ K♠ Q♠ 7♠ K♦ A♠ |
~/$ ./p2 Shuffle: [n | s | u <seed>]: u 2018 10♥ 10♠ K♥ J♠ ⋮ 8♦ 8♥ 5♦ J♣ 2♥ |
~/$ ./p2 Shuffle: [n | s | u <seed>]: s Q♥ J♣ J♥ DIFFERENT 2♣ EVERY ⋮ TIME K♥ YOU 10♦ RUN IT 6♦ K♦ Q♣ |
part3.cppNote: You really want to have your program simulate dealing a card to a hand. You should be able to point to few variables and say "those represent the player's hand," and point to a few more and say "those represent the dealer's hand."
| Sample runs: red text represents user input, brown text is explanatory and not part of the output | |||
~/$ ./p3 Shuffle: [n | s | u <seed>]: u 42 ← deck:K♠ 10♦ 2♦ 10♠ Q♥ 4♦ K♥ J♠ 7♥ 2♥ 8♦ Q♠ 3♥ 8♣ … Player Dealer | K♠ | 10♦ | | 2♦ | 10♠ | ← deck:K♠ 10♦ 2♦ 10♠ Q♥ 4♦ K♥ J♠ 7♥ 2♥ 8♦ Q♠ 3♥ 8♣ … Player Dealer | K♠ | 10♦ | | 2♦ | 10♠ | | Q♥ | 4♦ | ← deck:K♠ 10♦ 2♦ 10♠ Q♥ 4♦ K♥ J♠ 7♥ 2♥ 8♦ Q♠ 3♥ 8♣ … Player Dealer | K♠ | 10♦ | | 2♦ | 10♠ | | Q♥ | 4♦ | | K♥ | J♠ | ← deck:K♠ 10♦ 2♦ 10♠ Q♥ 4♦ K♥ J♠ 7♥ 2♥ 8♦ Q♠ 3♥ 8♣ … Player Dealer | K♠ | 10♦ | | 2♦ | 10♠ | | Q♥ | 4♦ | | K♥ | J♠ | | 7♥ | 2♥ | |
~/$ ./p3 Shuffle: [n | s | u <seed>]: u 314 Player Dealer | J♠ | 4♣ | | 5♦ | 7♥ | Player Dealer | J♠ | 4♣ | | 5♦ | 7♥ | | 8♠ | 6♣ | Player Dealer | J♠ | 4♣ | | 5♦ | 7♥ | | 8♠ | 6♣ | | 8♦ | J♥ | Player Dealer | J♠ | 4♣ | | 5♦ | 7♥ | | 8♠ | 6♣ | | 8♦ | J♥ | | Q♦ | Q♠ | | ~/$ ./p3 Shuffle: [n | s | u <seed>]: u 9376 Player Dealer | 3♦ | 9♣ | | Q♥ | J♥ | Player Dealer | 3♦ | 9♣ | | Q♥ | J♥ | | 10♥ | 9♠ | Player Dealer | 3♦ | 9♣ | | Q♥ | J♥ | | 10♥ | 9♠ | | 8♣ | 2♥ | Player Dealer | 3♦ | 9♣ | | Q♥ | J♥ | | 10♥ | 9♠ | | 8♣ | 2♥ | | 6♦ | A♣ | |
|
part4.cppsystem("clear"); to clear the
terminal window, so that only the current state of the game is
showing at any given time.
Below is an example of how a game might play out. Your output
and the way you get input from the user must match what's
shown here.
Note: In the submit system, each call to
system("clear") shows up as the character sequence:
[H[2J
| Sample run: red text represents user input | |||
~/$ ./p4 Shuffle: [n | s | u <seed>]: u 103 |
Player Dealer
| 7♥ | Q♦ |
| K♥ | 2♠ |
Round 1 Player's turn
hit or stand? [h/s] h |
Player Dealer
| 7♥ | Q♦ |
| K♥ | 2♠ |
| J♣ | |
Round 1 Dealer's turn
hit or stand? [h/s] h |
|
Player Dealer
| 7♥ | Q♦ |
| K♥ | 2♠ |
| J♣ | 4♣ |
Round 2 Player's turn
hit or stand? [h/s] s |
Player Dealer
| 7♥ | Q♦ |
| K♥ | 2♠ |
| J♣ | 4♣ |
Round 2 Dealer's turn
hit or stand? [h/s] h |
||
Player Dealer
| 7♥ | Q♦ |
| K♥ | 2♠ |
| J♣ | 4♣ |
| | A♥ |
Round 3 Player's turn
hit or stand? [h/s] s |
Player Dealer
| 7♥ | Q♦ |
| K♥ | 2♠ |
| J♣ | 4♣ |
| | A♥ |
Round 3 Dealer's turn
hit or stand? [h/s] h |
Player Dealer | 7♥ | Q♦ | | K♥ | 2♠ | | J♣ | 4♣ | | | A♥ | | | 7♦ | | |
part5.cpp
| Sample run: red text represents user input | |||
~/$ ./p5 Shuffle: [n | s | u <seed>]: u 92 |
Player Dealer
| Q♦ | A♣ |
| 8♣ | 7♣ |
Player 18, Dealer 18
Round 1 Player's turn
hit or stand? [h/s] s
|
Player Dealer
| Q♦ | A♣ |
| 8♣ | 7♣ |
Player 18, Dealer 18
Round 1 Dealer's turn
hit or stand? [h/s] h
|
Notice that the A♣ is counted as 11 points int the dealer's hand |
Player Dealer
| Q♦ | A♣ |
| 8♣ | 7♣ |
| | 6♠ |
Player 18, Dealer 14
Round 2 Player's turn
hit or stand? [h/s] s
|
Player Dealer
| Q♦ | A♣ |
| 8♣ | 7♣ |
| | 6♠ |
Player 18, Dealer 14
Round 2 Dealer's turn
hit or stand? [h/s] h
|
Notice that the A♣ is is now counted as just 1 point in the dealer's hand | |
Player Dealer
| Q♦ | A♣ |
| 8♣ | 7♣ |
| | 6♠ |
| | 4♥ |
Player 18, Dealer 18
Round 3 Player's turn
hit or stand? [h/s] h
|
Player Dealer
| Q♦ | A♣ |
| 8♣ | 7♣ |
| 2♣ | 6♠ |
| | 4♥ |
Player 20, Dealer 18
Round 3 Dealer's turn
hit or stand? [h/s] h
|
Player Dealer | Q♦ | A♣ | | 8♣ | 7♣ | | 2♣ | 6♠ | | | 4♥ | | | 9♠ | | |
part6.cppsleep(2) (this will require
#include <unistd.h>)
to pause the game for two seconds so that the user has a
chance to see what the Dealer is doing before being
presented with the updated screen.
| Sample run: red text represents user input | ||
~/$ ./p6 Shuffle: [n | s | u <seed>]: u 314 |
Player Dealer
| J♠ | 4♣ |
| 5♦ | 7♥ |
Player 15, Dealer 11
Round 1 Player's turn
hit or stand? [h/s] s
|
Player Dealer
| J♠ | 4♣ |
| 5♦ | 7♥ |
Player 15, Dealer 11
Round 1 Dealer's turn
hit or stand? [h/s] h
|
Player Dealer
| J♠ | 4♣ |
| 5♦ | 7♥ |
| | 8♠ |
Player 15, Dealer 19
Round 2 Player's turn
hit or stand? [h/s] h
|
Player Dealer
| J♠ | 4♣ |
| 5♦ | 7♥ |
| 6♣ | 8♠ |
Player 21, Dealer 19
Round 2 Dealer's turn
hit or stand? [h/s] s
|
|
| Note: The game stops because of consecutive "stand" moves. |
Player Dealer
| J♠ | 4♣ |
| 5♦ | 7♥ |
| 6♣ | 8♠ |
Player 21, Dealer 19
Round 3 Player's turn
hit or stand? [h/s] s
|
Player Dealer | J♠ | 4♣ | | 5♦ | 7♥ | | 6♣ | 8♠ | Player 21, Dealer 19 |
| Sample run: red text represents user input | |||
~/$ ./p6 Shuffle: [n | s | u <seed>]: u 349 |
Player Dealer
| J♦ | A♠ |
| 8♣ | 6♠ |
Player 18, Dealer 17
Round 1 Player's turn
hit or stand? [h/s] h
|
Player Dealer | J♦ | A♠ | | 8♣ | 6♠ | | 5♥ | | Player 23, Dealer 17 |
Note: The game stops because the Player "busts". Hitting on 18 was crazy! |
part7.cpp** until the end of the game. This way, the
Player has some uncertainty about what to do.
| Sample run: red text represents user input | |||
~/$ ./p7 Shuffle: [n | s | u <seed>]: u 901 |
Player Dealer
| Q♣ | ** |
| K♣ | 7♦ |
Round 1 Player's turn
hit or stand? [h/s] s
|
Player Dealer
| Q♣ | ** |
| K♣ | 7♦ |
Round 1 Dealer's turn
hit or stand? [h/s] s
|
Player Dealer | Q♣ | A♦ | | K♣ | 7♦ | Player wins |
| Sample run: red text represents user input | |||
~/$ ./p7 Shuffle: [n | s | u <seed>]: u 500 |
Player Dealer
| K♠ | ** |
| 7♣ | 2♣ |
Round 1 Player's turn
hit or stand? [h/s] s
|
Player Dealer
| K♠ | ** |
| 7♣ | 2♣ |
Round 1 Dealer's turn
hit or stand? [h/s] h
|
|
Player Dealer
| K♠ | ** |
| 7♣ | 2♣ |
| | 2♠ |
Round 2 Player's turn
hit or stand? [h/s] s
|
Player Dealer
| K♠ | ** |
| 7♣ | 2♣ |
| | 2♠ |
Round 2 Dealer's turn
hit or stand? [h/s] h
|
||
Player Dealer
| K♠ | ** |
| 7♣ | 2♣ |
| | 2♠ |
| | 3♦ |
Round 3 Player's turn
hit or stand? [h/s] s
|
Player Dealer
| K♠ | ** |
| 7♣ | 2♣ |
| | 2♠ |
| | 3♦ |
Round 3 Dealer's turn
hit or stand? [h/s] s
|
Player Dealer | K♠ | Q♠ | | 7♣ | 2♣ | | | 2♠ | | | 3♦ | | |
Player Dealer
| 8♣ | ** |
| A♦ | J♥ |
Round 1 Player's turn
hit or stand? [h/s] s
|
Player Dealer
| 8♣ | ** |
| A♦ | J♥ |
Round 1 Dealer's turn
hit or stand? [h/s] h
|
||
Player Dealer
| 8♣ | ** |
| A♦ | J♥ |
| | A♥ |
Round 2 Player's turn
hit or stand? [h/s] h
|
Player Dealer
| 8♣ | ** |
| A♦ | J♥ |
| 6♥ | A♥ |
Round 2 Dealer's turn
hit or stand? [h/s] h
|
Player Dealer | 8♣ | 5♦ | | A♦ | J♥ | | 6♥ | A♥ | | | 10♣ | Dealer busts, player wins | |
partX.cpp
~/bin/submit -c=IC210 -p=proj02 part1.cppThe full Project 2 submission is due by COB on Monday, October 31st, according to the course's particular definition of "COB". Late projects incur a penalty of 3N points, where N is the number of days late. So, a project that is not turned in by COB Monday, 31 October, but which is turned in by COB Tuesday receives a 3 point penalty. A project that is not turned in by COB Tuesday, but which is turned in by COB Wednesday receives a 9 point penalty. And so on. You will submit with:
~/bin/submit -c=IC210 -p=proj02 part1.cpp part2.cpp part3.cpp part4.cpp part5.cpp part6.cpp part7.cpp partX.cpp
~/bin/submit -c=IC210 -p=proj02 part1.cpp part2.cpp part3.cpp part4.cpp part5.cpp part6.cpp part7.cpp partX.cpp