Main.Assignment11 History
Hide minor edits - Show changes to markup
Assignment 11
Assignment 11
The game of war
The game of war
1 if player 1 wins, 2
Assignment 11
Due April 26th
The game of war
Your task this week is to write a program that plays the game of war. Most of us have probably played this game as kids. It's a card game of pure chance. In case you don't remember the rules, and to have a specific set of rules we will play the game as described in this wikipedia article.
Decompose the task of simulating the game into a collection of objects that interact and use each other.
The game itself will be modeled by a class class called WarGame. The game requires two player hands that you can represent using two instances of a class called Hand. A hand contains a list of Card objects that are dealt from a Deck of cards. You may also want to define a class called Player that will contain a player's hand, and will be used by the WarGame class in playing the game. Define the methods that you think are necessary; before you start writing the code lay out the structure of the classes and their functionality. Each class you write should have a __repr__() method that provides useful information.
The class WarGame should have a method called play() that plays the game. It should print information that will allow to follow the progression of the game. It should return a tuple that contains the following information:
(winning_player, num_battles, num_wars)
winning_player is 1 if player 1 won and 2 if player 2 won;
num_battles is the number of battles in the game; num_wars is the number of wars.
1 if player 1 wins, 2
Submit your program in a module called war.py.
This assignment can be written in pairs.
