### CSC 427: Data Structures and Algorithm Analysis Fall 2004 HW2: Classes and Vectors

For this assignment, you will be using the Card and DeckOfCards classes (defined in Cards.h and Cards.cpp) to simulate the card game War. In this game, a deck of cards is shuffled and cards are alternately dealt into two piles until the deck is exhausted. One round of play consists of each player drawing from the top of his/her "active" pile of cards. The player whose card has the higher rank wins the round and consequently places both drawn cards in a separate "conquest" pile for that player. When a tie occurs, e.g., two kings, a battle between the two players ensues, where the players lay down cards in multiples of three until a winner is declared. In practice, the outcome of games is often determined by the players' fortunes in these battles. For example, the only way to capture the other player's aces is in battles. When a player runs out of cards in his/her active pile, that player's conquest pile is shuffled and then serves as the active pile from that point on. If the player has no cards in either pile, then that player loses.

Note: you may want to define a PileOfCards class to encapsulate the functionality of card piles in this game.

### Simplified Version: Tie = Random (for 80% credit)

It is strongly recommended that you first implement your War game so that ties are handled in a simple way. When a tie occurs, randomly award the cards to one of the players. This will simplify the game and make it easier to test and debug the other aspects of the game. The output of your simulated game should look something like the following (feel free to creatively embellish your output). 1) Player 1: 4C Player 2: TH Player 2 wins. 2) Player 1: 2D Player 2: AH Player 2 wins. 3) Player 1: JC Player 2: JS Tie -- Player 2 wins. 4) Player 1: 9H Player 2: 3D Player 1 wins. . . . 548) Player 1: 5H Player 2: AS Player 2 wins. Player 1 is out of cards. Player 2 wins!

### Full Version: Tie = Battle (for 100% credit)

In the full version of War, a battle occurs whenever the cards drawn by the two players have equal rank. A battle consists of each player drawing three cards from the top of his/her active pile and placing them in a battle pile. The cards on the tops of these battle piles are compared to determine the winner, who takes the contents of both battle piles and adds them to his/her conquest pile. If the cards on the top of the battle piles have the same rank again, three more cards are drawn and the battle continues until a winner is determined. For example, 1) Player 1: 4C Player 2: TH Player 2 wins. 2) Player 1: 2D Player 2: AH Player 2 wins. 3) Player 1: JC Player 2: JS Tie -- a battle ensues... Player 1: 9H Player 2: 3D I Player 1: QH Player 2: AD DECLARE Player 1: 5D Player 2: 3H WAR -- Player 1 wins. 4) Player 1: AC Player 2: KH Player 1 wins. . . . 486) Player 1: 8D Player 2: QS Player 2 wins. Player 1 is out of cards. Player 2 wins!

If a player is unable to complete a battle due to lack of cards, then he/she forfeits the battle and loses the game. For example, suppose a tie occurs and a battle ensues but Player 2 only has 2 cards in his/her active pile. If Player 2's conquest pile is nonempty, then that pile is shuffled and becomes his/her active deck and battle continues. If the conquest deck is empty, however, then Player 2 would forfeit the battle and lose the game.