Homework 1, Florin Marches off to War
Short Description:
Write a series of programs to study the game of War.
This assignment is worth 100 points.
Goals
When you finish this homework, you should:
- Have declared and used enumerated types.
- Have declared and used simple records.
- Have built a project from multiple files.
Formal Description
After your success with the Ministry of Foreign Information, the Florin
Ministry of War has hired you. The Ministry of War is interested in studying
the card game War to see if it might be an acceptable alternative for solving
conflicts with Guilder. To accomplish this, the Ministry has asked you to
produce the following programs.
Please see the wikipedia War (card game) entry for the rules of this game.
- War: This program simulates a two player game of war.
- WarStats: This program should play 100 games of war and compute
the statistics similar to those on the wikipedia page.
In order to better simulate human players, whenever a battle occurs, decide
at random which cards are placed into the winning players hand first.
Algorithm for the winner:
Flip a coin
If the result is heads
place your cards in your deck
place your opponents cards in your deck
else
place your opponents cards in your deck
place your cards in your deck
War
Your program should provide an easy to read, detailed dialog describing the
game. The following is the suggested output format. You may need to
extend this format for situations not covered in this example.
Welcome to War.
Dealing the cards.
Battle 1
Player 1 plays an Ace of Hearts
Player 2 plays a Queen of Spaces
Player 1 wins
Player 1 places
the Queen of Spades
then the Ace of hearts in their hand.
Battle 2
Player 1 plays a Two of Clubs
Player 2 plays a Two of Diamonds
WAR!
Player 1 puts a Queen of Clubs in the battle
Player 1 puts a Five of Hearts in the battle
Player 1 puts a Seven of Diamonds in the battle
Player 2 puts a Four of Clubs in the battle
Player 2 puts a Nine of Clubs in the battle
Player 2 puts a Five of Diamonds in the battle
Player 1 plays a Seven of Spades
Player 2 plays a Four of Diamonds
Player 1 wins.
Player 1 places the Two of Clubs
then the Queen of Clubs
then the Five of Hearts
then the Seven of Diamonds
then the Seven of Spades
then the Two of Diamonds
then the Four of Clubs
then the Nine of Clubs
then the Five of Diamonds
then the Four of Diamonds in their hand
...
Battle 483
Player 1 plays a Two of Hearts
Player 2 plays an Ace of Spades
Player 2 wins
Player 2 places the Ace of Spades
then the Two of Hearts in their hand.
Battle 484
Player 1 is out of cards
Player 2 wins.
WarStats
Your program should run 500 simulated battles. After each battle print a report
Battle 1, Player 2 wins in 483 battles. 12 Wars, 1 double War.
When the program is complete, print a summary of
- Average, maximum and minimum number of battles per game.
- Average, maximum and minimum number of single wars per game.
- Average, maximum and minimum number of double wars per game.
- Average, maximum and minimum number of other wars per game.
Discussion
- You must represent cards as a record.
- You must represent the suit of a card as an enumerated type.
- You must represent card rank as an enumerated type.
- You must define your cards, types, and associated routines in a specification file.
- You must use my file deck.h for decks, hands and other collections of cards.
- You must implement your card related utility routines in an implementation file.
- Whenever possible, eliminate repeated code by building subroutines. If you find you are repeating code, pull it out and put it into a subroutine.
- You should probably do a preliminary design on this set of programs.
- You should probably write some experimental code, and then revise your design.
- You should create a sub-directory and perform all work for this project within this directory. This will make the creation of the tar file easier.
- If you need help, you should ask.
- Please do not put this work off until the weekend before it is due.
- You should conform to all style guidelines including naming conventions and the use of constants.
Files you need.
You will need a copy of my file deck.h. You might also want my Makefile and my example driver file.
Required Files
You should submit the following in a tar file:
- All source code required to build all programs.
- A Makefile which will build all programs as well as clean the directory
- A README describing
- Author identification information
- The project
- Problems encountered
- Any portions of the code which are not working.
- Any unique features of the code.
- Any other information you wish to share.
You should not submit
- Object files or executable.
- Core files.
- Source code files which are not related to the project.
Submission
Please create a tar file containing the files described above. Email this file to danbennett360@gmail.com by class time of the due date.