Intro to Computer Science
Code AND WORKSHEET due by Friday, Mar 2nd at 9:00 AM
Come on admit it. Somewhere along the line as a kid (at least those of you who grew up in the US) you played the card game called War. It's a simple two-player game. You divide a deck (or multiple decks) of cards into two, and each player gets half the cards. Next, each player turns over the top card of their decks. If player 1 has the higher card, player 1 wins that round and takes both cards. Both the card totals are added to player 1's score. If player 2 has the higher card, player 2 wins that round and takes both cards. Both the card totals are added to player 2's score. If there is a tie, different things can happen, depending on the rules.
The game is often seen as a game of chance. Whichever player wins is random, similar to flipping a coin or throwing a dice randomly.
Original Program Specifications
Before starting your code, read through the program specification below and fill in the worksheet for each task/subtask you will need to perform
Your program (saved in a file called noWar.py) will allow a human user to play several rounds of War with the computer. Each round of the game will have the following structure:
For example, one sample game might look like this:
For this version of this game, you must program the computer to pick cards randomly. To do this you should put the following code at the top of your program:
import random random.seed()
This is the code necessary to set up a random number generator.
Each time you need to pick a random number you use:
This will produce a value from 1 to 13 INCLUSIVE (notice this is different from the way range works). 1=Ace, 2=2, 3=3 ... 10=10, 11=Jack, 12=Queen, and 13=King.
Getting Started (Worksheet)
Once you can do all that, be sure all the code you have works before moving on to the next subtask.
BONUS PROBLEM worth 3 extra points- Let's declare a real war!
On tie, both players keep flipping cards until the tie is broken. In a more typical game, only the player that wins the tie break at the end will get points. In this version, all cards involved in the tie(s) and subsequent win should be added to the winning player's score, and no points should be added to the loosing players score. See this example run:
Name this version of the game war.py. Only work on this once you have the previous version of the game working and saved in a separate loation. If you finish war.py, you only need to submit this copy of the game. It is very important that you name the program correctly to signal us to check for the extra credit.
To upload your homework for grading, log on to eLearning, select this class, and navigate to the "Assignment Submissions" area. Click on the "Programming Assignment 5" folder and upload the following files to the designated location: