C++代写:CSE332 Multiple Card Games

复用之前的代码框架,代写一个较为复杂的卡牌游戏,练习C++ STL库的使用方法。

Objective

This lab is intended to combine and extend your use of C++ language features from the previous labs, and to give you more experience programming with the C++ STL. To do this, you will extend your C++ programs from the previous labs to (1) add a new game (Seven Card Stud) in addition to the Five Card Draw game from lab 3 (which you will enhance in this lab), (2) manage different numbers and kinds of player turns in the two games, (3) find the highest ranking combination of cards for each player in each of those games and rank the players accordingly, and (4) add features to both games so that players win or lose chips in each round of play.

For extra credit, you may optionally implement (5) an additional game (Texas Hold ‘Em).

In this lab, you are again encouraged to re-use and modify code from your previous lab solutions - if you choose do this, please put a completely new copy of any header and source files from your previous lab(s) in the new lab project directory you create. This can avoid some potential for error or confusion within Visual Studio, and also ensures you have a backup copy that you could go back to if a modification you try doesn’t pan out.

In this lab you may work individually, or in teams of 2 or 3 (but not more) people. Team projects may use any of the team members’ previous code in the team’s solution.

Assignment

Readings

Please make sure to review and apply all of the CSE 332 Programming Guidelines as you implement your solution.

Program Design and Implementation

Note: the details of this assignment are again intentionally somewhat under-specified, leaving you some room to choose what you think is the best way to implement them, as long as what you do is reasonable and you explain your design decisions in comments in the code and in your Readme.txt file.

For this lab assignment, you are especially encouraged to think creatively about how to structure (or restructure) the turn and round methods (including the before, during, and after phases of each): some potentially useful ideas may include having more turns per round, introducing addtional member variables to indicate the different stages of play in each game, or interspersing betting phases with play phases in different ways.

Step 1

Open up Visual Studio, and create a new Win32 Console Application Visual C++ project for lab 4. Copy the files you wish to re-use from your lab 3 solution (or solutions if a team project) into the source/header files directory for your lab 4 project and add them to the project.

Step 2

Please add an unsigned integer member variable to your Player class to keep track of how many chips the player has. When a player is constructed this variable should be initialized with 20. When players quit or re-join either game, this value (along with their wins and losses) should be stored to or restored from a file (as was done for other information in the previous lab) for that player.

As each player plays they will win or lose chips during betting phases that will occur at different points in each game, and if a player’s chip count is ever 0 after a round the player should be prompted (and required) either to reset their chip count to 20 and keep playing, or to quit the game. If a player with 0 chips quits the game and then tries to rejoin the game, they should be required either to reset their chip count to 20 and keep playing, or not rejoin the game after all.

Step 3

Please update your FiveCardDraw class so that:

  • Before each round an ante of one chip should be deducted from each player’s chip count and added to a common pot of chips that will go to the winner of the round.

  • During each of two betting phases in each round (one phase before cards are drawn and one after cards are drawn) the program should rotate among the remaining players, prompt each player for which action to take (and how many chips to bet or raise for those actions), deduct the chips each player bets, calls, or raises from their chip total, and should also record the cumulative amount they have bet during that phase (to be able to know how many chips are needed to call any previous bets or raises that phase, etc. - see next).
    During a phase, if no other player has bet so far, the next player may either check (staying in the round but not risking any more chips at that point) or bet either 1 or 2 chips.
    Once a player does bet during a phase, then the other players must either fold (dropping out of the round and having their chips bet so far in that round pushed into the pot), call all previous bets and raises that they have not called (by increasing their cumulative number of chips bet to match the highest cumulative bet of any other player in the phase so far), or raise 1 or 2 chips in addition to the amount needed to call any earlier bet or raise.
    If a player runs out of chips during a phase, they will remain in the round with no further obligation to call, bet, or raise in that phase (or any subsequent phase) until the round is over. For simplicity they will be able to win the entire pot (or a split of it in the case of a tie) if their hand is highest (if you would like to do so you may instead choose to implement support for side pots, though it is not required to do so).
    If all players check and no-one bets the phase simply ends without any chips being added to the pot. If someone does bet the phase continues until the most recent bet or raise has been called by all remaining players or until all but one player has folded. At the end of the phase all chips bet (including those by players who later folded) are pushed into the pot.
    If all players except one decide to fold, then the entire pot is awarded to the remaining player, their win count is increased by one, and the round ends.
    Otherwise after the last betting phase of a round the hands of the players that remain are ranked, the pot is added to the chip count of the player with the highest hand (or is split among the players having identically highest hands if there are ties at the top), and the winning player(s) win count is increased by one and the other remaing players loss counts are increased by one.

  • At the end of each round the game should print out each player’s name, wins, losses, and chip counts, and either their hands if they stayed in until the end of the round or an indication that they folded without showing down their hand.

Step 4

Please add a SevenCardStud class. Make sure that it implements all of the common features of your FiveCardDraw solution, and in fact one good approach is to move as much common functionality as possible up into (possibly private) methods of the Game class or of an intermediate class (e.g., PokerGame which is derived from Game ) . For example collecting antes, saving and restoring players, handling the cases where a player runs out of chips during a round, announcing the winner(s) at the end of each round, etc. should work essentially the same in all games.

Please implement the following features in your SevenCardStud class:

  • Each round should consist of multiple turns, with a betting phase after each turn.

  • Some of each player’s cards will be dealt “face down” and are only visible to them until the hands of the remaining players are ranked at the end of the round. The rest of the cards are dealt “face up” and are visible to all players. During each player’s turn, the cards dealt so far should be displayed as follows: all of the cards in that player’s hand should be printed out, as should the face up cards in the other remaining players’ hands, but each of the face down cards in the other players’ hands should be represented by printing an asterisk (‘*’).

  • In the first turn each player should be dealt two face down cards and then one face up card.

  • In each of the second, third, and fourth turns each remaining player should be dealt an additional face up card.

  • In the fifth and final turn each player should be dealt one additional face down card.

  • The play of the betting phases will be the same as in the FiveCardDraw game, except that there will be five phases instead of two.

  • Unlike FiveCardDraw in which each remaining player will have exactly 5 cards in their hand, in SevenCardStud each player still in the round when it ends will have 7 cards from which to choose their best 5 cards. For each remaining player at the end of each round (unless all but one have already folded) your SevenCardStud game should choose the highest ranking combination of 5 of their seven cards, and use each player’s best possible hand to determine the winner(s) of the round.

Step 5

Please update your Game class and your main function so that (1) “SevenCardStud” is recognized as a valid name of a game, and when it is provided should result in a SevenCardStud game being created and played; and (2) after any game is finished the program should stop (and destroy) the previous game and then prompt the user whether to play a new game or quit the program. If the user chooses to play a new game the program should prompt for the name of the game and the names of the players (re-prompting for whether to quit or play again etc. as needed if an invalid game name is given).

If at any point the program encounters an error that will not allow it to continue, it should generate an error message and return an approprate non-zero error code.

Step 6

Build your project, and fix any errors or warnings that occur. Please be sure to note all of the different kinds of errors or warnings you ran into (though you don’t have to list every instance of each kind) in your ReadMe.txt file. If you were fortunate enough not to run into any errors or warnings, please note that instead, where you would have listed errors or warnings in your ReadMe.txt file.

Step 7

Open up a Windows console (terminal) window and change to the directory where your program’s executable file was created by Visual Studio, and run the executable program through a series of trials that test it with good coverage of cases involving both well formed and badly formed inputs. In your ReadMe.txt file please document which cases you ran (i.e., what the command lines were) and summarize what your program did and whether that is correct behavior, in each case.

Step 8

In your ReadMe.txt file, make sure that your name (or names_ and the lab number (lab 4) are at the top of the file, and that you’ve documented whether you ran into any errors or warnings while developing your solution (and if so what they were) and what the executable program did for each of the trials you ran. Be sure to save your changes to your ReadMe.txt file, as well as those to your source (and header) file(s) before preparing your solution zip file.

Step 9

Prepare a zip file that contains your project’s source, header, and ReadMe.txt files (except for stdafx.h, stdafx.cpp or other Windows-generated files you did not modify), by:

  • Creating a new lab4 folder on your Windows desktop;
  • Copying the appropriate files (here, ReadMe.txt, and the source and header files where you wrote your code) from Visual Studio into that folder; and then
  • Right-clicking on the folder and selecting the Send To->Compressed (zipped) Folder item in the menu that appears.

Extra Credit

The goal of the additional requirements for extra credit is to add a third game (Texas Hold ‘Em).
To do that, you should implement the following additional features.

Step 10

Please add a TexasHoldEm class. Make sure that it implements all of the common features of your FiveCardDraw and SevenCardStud solutions, and as noted earlier one good approach is to move as much common functionality as possible up into (possibly private) methods of a common base class. For example collecting antes, saving and restoring players, handling the cases where a player runs out of chips during a round, announcing the winner(s) at the end of each round, etc. should work essentially the same in all games.

Please implement the following features in your TexasHoldEm class:

  • Each round should again consist of multiple turns, with a betting phase after each turn.

  • Each player will be dealt two “face down” cards that are only visible to them until the hands of the remaining players are ranked at the end of the round. The rest of the cards are dealt “face up” and are visible to and are shared by all players. During each player’s turn, that player’s face down cards should be printed out, as should any face up cards shared by all players, while each of the other players’ face down cards in should be represented by asterisks (“ “).

  • In the first turn each player should be dealt two face down cards.

  • In the second turn three face up cards shared by all players (the “flop”) should be dealt.

  • In each of the third and fourth turns an additional face up card (the “turn” and “river” cards) shared by all players should be dealt.

  • The play of the betting phases will be the same as in the FiveCardDraw game, except that there will be four phases instead of two.

  • Unlike FiveCardDraw and SevenCardStud in which each remaining player will have their own cards, in TexasHoldEm each player still in the round when it ends will choose their best 5 cards made up from the 7 cards including the 2 cards dealt to them and the 5 cards shared by all players in that round. For each remaining player at the end of each round (unless all but one have already folded) your SevenCardStud game should choose the highest ranking combination of 5 of those seven cards, and use them to determine the winner(s) of the round.

Step 11

Please update your Game class and your main function so that “TexasHoldEm” is recognized as a valid name of a game, and when it is provided should result in a TexasHoldEm game being created and played.