CMSC 201
Programming Project Two

War - A Card Game

Out: Wednesday 2/27/02
Due: Before Midnight, Wednesday 3/13/02

The design document for this project, design2.txt ,
is due: Before Midnight, Wednesday 3/06/02

Addition of Specific Requirements section on 3/1/02

Objective

The objective of this assignment is to give you practice with project and function design. It will also give you an opportunity to work with random numbers, arrays, passing arrays to functions, and using separate compilation.

War - A Modified Version of the Card Game

Your program will simulate the playing of a game of war with some minor modifications so that the game finishes within a resonable amount of time. The computer will handle the playing of cards by both of the players.

Our rules -

While testing various seeds for the random number generator, I was surprised at how many times there were cards left in the tie pile at game's end. You will also investigate this by having your program play this game 100 times, using the numbers 1 through 100 as seeds for the random number generator. You must then report the number of games that ended with cards left in the tie pile.

Make sure that you print an explanation of the game to the user and have him press ENTER to begin the playing of the games. Otherwise the explanation will scroll off of the screen before the user gets to read it.

Specific Requirements

You must use two arrays of size 26 to hold the cards dealt to the player and to the computer. You must also use an array of counters when dealing so that you can guarantee that exactly four cards of each rank are dealt.

A Sample Run

Note - I'm only showing the beginning and the end of the sample run, since it is very long. What I've shown is enough to show you what is expected. It's WAR !!! Your explanation of the game for the user goes here . . . Press ENTER to begin : Seed = 1 : Hand 1 : You played a 1 and I played a 10 So I won these cards You have won 0 cards and I have won 2 cards There are 0 cards in the Tie pile Hand 2 : You played a 12 and I played a 5 So you won these cards You have won 2 cards and I have won 2 cards There are 0 cards in the Tie pile Hand 3 : You played a 2 and I played a 2 It was a tie You have won 2 cards and I have won 2 cards There are 2 cards in the Tie pile Hand 4 : You played a 13 and I played a 4 So you won these cards You have won 6 cards and I have won 2 cards There are 0 cards in the Tie pile Hand 5 : You played a 2 and I played a 8 So I won these cards You have won 6 cards and I have won 4 cards There are 0 cards in the Tie pile Hand 6 : You played a 3 and I played a 4 So I won these cards You have won 6 cards and I have won 6 cards There are 0 cards in the Tie pile Hand 7 : You played a 1 and I played a 5 So I won these cards You have won 6 cards and I have won 8 cards There are 0 cards in the Tie pile Hand 8 : You played a 13 and I played a 2 So you won these cards You have won 8 cards and I have won 8 cards There are 0 cards in the Tie pile Hand 9 : You played a 10 and I played a 11 So I won these cards You have won 8 cards and I have won 10 cards There are 0 cards in the Tie pile Hand 10 : You played a 11 and I played a 12 So I won these cards You have won 8 cards and I have won 12 cards There are 0 cards in the Tie pile Hand 11 : You played a 8 and I played a 9 So I won these cards You have won 8 cards and I have won 14 cards There are 0 cards in the Tie pile Hand 12 : You played a 4 and I played a 4 It was a tie You have won 8 cards and I have won 14 cards There are 2 cards in the Tie pile Hand 13 : You played a 6 and I played a 3 So you won these cards You have won 12 cards and I have won 14 cards There are 0 cards in the Tie pile Hand 14 : You played a 11 and I played a 5 So you won these cards You have won 14 cards and I have won 14 cards There are 0 cards in the Tie pile Hand 15 : You played a 10 and I played a 13 So I won these cards You have won 14 cards and I have won 16 cards There are 0 cards in the Tie pile Hand 16 : You played a 10 and I played a 6 So you won these cards You have won 16 cards and I have won 16 cards There are 0 cards in the Tie pile Hand 17 : You played a 5 and I played a 11 So I won these cards You have won 16 cards and I have won 18 cards There are 0 cards in the Tie pile Hand 18 : You played a 6 and I played a 12 So I won these cards You have won 16 cards and I have won 20 cards There are 0 cards in the Tie pile Hand 19 : You played a 12 and I played a 6 So you won these cards You have won 18 cards and I have won 20 cards There are 0 cards in the Tie pile Hand 20 : You played a 1 and I played a 3 So I won these cards You have won 18 cards and I have won 22 cards There are 0 cards in the Tie pile Hand 21 : You played a 1 and I played a 3 So I won these cards You have won 18 cards and I have won 24 cards There are 0 cards in the Tie pile Hand 22 : You played a 7 and I played a 7 It was a tie You have won 18 cards and I have won 24 cards There are 2 cards in the Tie pile Hand 23 : You played a 13 and I played a 8 So you won these cards You have won 22 cards and I have won 24 cards There are 0 cards in the Tie pile Hand 24 : You played a 8 and I played a 7 So you won these cards You have won 24 cards and I have won 24 cards There are 0 cards in the Tie pile Hand 25 : You played a 9 and I played a 9 It was a tie You have won 24 cards and I have won 24 cards There are 2 cards in the Tie pile Hand 26 : You played a 7 and I played a 9 So I won these cards You have won 24 cards and I have won 28 cards There are 0 cards in the Tie pile Results : I WON !!! Seed = 2 : Hand 1 : You played a 5 and I played a 2 So you won these cards You have won 2 cards and I have won 0 cards There are 0 cards in the Tie pile Hand 2 : You played a 7 and I played a 1 So you won these cards You have won 4 cards and I have won 0 cards There are 0 cards in the Tie pile Hand 3 : You played a 8 and I played a 1 So you won these cards You have won 6 cards and I have won 0 cards There are 0 cards in the Tie pile Hand 4 : You played a 13 and I played a 4 So you won these cards You have won 8 cards and I have won 0 cards There are 0 cards in the Tie pile Hand 5 : You played a 8 and I played a 1 . . . Hand 26 : You played a 7 and I played a 7 It was a tie You have won 26 cards and I have won 24 cards There are 2 cards in the Tie pile Results : YOU WON !!! Seed = 100 : Hand 1 : You played a 8 and I played a 2 So you won these cards You have won 2 cards and I have won 0 cards There are 0 cards in the Tie pile Hand 2 : You played a 10 and I played a 10 It was a tie You have won 2 cards and I have won 0 cards There are 2 cards in the Tie pile Hand 3 : You played a 4 and I played a 11 So I won these cards You have won 2 cards and I have won 4 cards There are 0 cards in the Tie pile Hand 4 : You played a 8 and I played a 10 So I won these cards You have won 2 cards and I have won 6 cards There are 0 cards in the Tie pile Hand 5 : You played a 6 and I played a 4 So you won these cards You have won 4 cards and I have won 6 cards There are 0 cards in the Tie pile Hand 6 : You played a 13 and I played a 12 So you won these cards You have won 6 cards and I have won 6 cards There are 0 cards in the Tie pile Hand 7 : You played a 13 and I played a 2 So you won these cards You have won 8 cards and I have won 6 cards There are 0 cards in the Tie pile Hand 8 : You played a 9 and I played a 9 It was a tie You have won 8 cards and I have won 6 cards There are 2 cards in the Tie pile Hand 9 : You played a 4 and I played a 10 So I won these cards You have won 8 cards and I have won 10 cards There are 0 cards in the Tie pile Hand 10 : You played a 4 and I played a 13 So I won these cards You have won 8 cards and I have won 12 cards There are 0 cards in the Tie pile Hand 11 : You played a 12 and I played a 1 So you won these cards You have won 10 cards and I have won 12 cards There are 0 cards in the Tie pile Hand 12 : You played a 12 and I played a 11 So you won these cards You have won 12 cards and I have won 12 cards There are 0 cards in the Tie pile Hand 13 : You played a 2 and I played a 12 So I won these cards You have won 12 cards and I have won 14 cards There are 0 cards in the Tie pile Hand 14 : You played a 6 and I played a 2 So you won these cards You have won 14 cards and I have won 14 cards There are 0 cards in the Tie pile Hand 15 : You played a 8 and I played a 5 So you won these cards You have won 16 cards and I have won 14 cards There are 0 cards in the Tie pile Hand 16 : You played a 5 and I played a 6 So I won these cards You have won 16 cards and I have won 16 cards There are 0 cards in the Tie pile Hand 17 : You played a 8 and I played a 3 So you won these cards You have won 18 cards and I have won 16 cards There are 0 cards in the Tie pile Hand 18 : You played a 9 and I played a 7 So you won these cards You have won 20 cards and I have won 16 cards There are 0 cards in the Tie pile Hand 19 : You played a 1 and I played a 5 So I won these cards You have won 20 cards and I have won 18 cards There are 0 cards in the Tie pile Hand 20 : You played a 11 and I played a 1 So you won these cards You have won 22 cards and I have won 18 cards There are 0 cards in the Tie pile Hand 21 : You played a 6 and I played a 13 So I won these cards You have won 22 cards and I have won 20 cards There are 0 cards in the Tie pile Hand 22 : You played a 11 and I played a 9 So you won these cards You have won 24 cards and I have won 20 cards There are 0 cards in the Tie pile Hand 23 : You played a 7 and I played a 7 It was a tie You have won 24 cards and I have won 20 cards There are 2 cards in the Tie pile Hand 24 : You played a 1 and I played a 5 So I won these cards You have won 24 cards and I have won 24 cards There are 0 cards in the Tie pile Hand 25 : You played a 3 and I played a 7 So I won these cards You have won 24 cards and I have won 26 cards There are 0 cards in the Tie pile Hand 26 : You played a 3 and I played a 3 It was a tie You have won 24 cards and I have won 26 cards There are 2 cards in the Tie pile Results : I WON !!! After 100 games, 44 games ended with the last cards played being the same linux3[73] %


What to Turn In

You must use separate compilation for this project and should have a file, called proj2.c, that contains the function main(). You should also have a war.c and war.h, that contain the functions used by proj2.c and the prototypes for those functions, respectively. Submit as follows: submit cs201 Proj2 proj2.c war.c war.h The order in which the files are listed doesn't matter. However, you must make sure that all files necessary to compile your project are listed.