# CPSC120BFundamentals of Computer Science I

## Assignment 6

Lists

Monopoly is a very competitive game played by people across the entire world. While there is a lot of luck involved in Monopoly, there is also a fair bit of strategy involved as well. Which real estate should you buy? The more real estate you own, the better. However that also costs a lot of money. The better strategy is to buy the locations that are most commonly landed on during the course of a Monopoly game. For this assignment, you will determine which spaces have the highest probability of being landed on.

### Details

You are going to represent a Monopoly board as a list of 40 integers. These integers are going to represent the count of the number of times an arbitrary player lands on a particular space. You are going to estimate this probability using the monte carlo method. You are going to start with a player at Go! (array index 0). You will generate 2 random numbers in the range $$[1, 6]$$ (You cannot generate a random number in the range $$[1, 12]$$, since this will not create the same distribution as a dice roll of two dice). This will move the player to a new location on the board, and you will increment the value in that space. You will then perform this again, with the player at the new location.

If the player lands on Go to Jail, you should send them directly to Jail.

There are a lot of other more obscure rules. We are not going to worry about these rules (Such as rolling doubles 3 times in a row, etc.). The rules listed above are the only rules you need to worry about.

You should run this process until the player has made 1,000 trips around the entire board. After the player has made the required number of trips around the board, you will output a list of all the probabilities for each of the locations on the board. The output should be nicely formatted so that you can use the image above to determine the board locations that have the highest probabiliby to be landed on during a single trip around the board.

### "Hacker" Prompt

Each week, additional exercises related to the assignment will be provided at the end. These exercises are typically more challenging than the regular assignment. Bonus points will be provided to students who complete any of the "Hacker" level assignments.

1. Doubles: In the real game of Monopoly, if you roll doubles 3 times in a row you go directly to jail. Modify your code above so that if a double is rolled 3 times in a row the user is sent directly to jail.

2. Chance and Community Chest: While you will get decent results from above, you can do better if you handle the Community Chest (2, 17, 33) and Chance (36, 22, 7) locations. These locations have a certain probability to send you to another location on the board. For the Community Chest, there is a $$\frac{1}{16}$$ chance of being sent to jail. For Chance, the distribution is a bit more complex:

$$\frac{1}{16}$$
Sent to Go! (00)
$$\frac{1}{16}$$
$$\frac{2}{16}$$
Sent to the closest Railroad (05, 15, 25, 35)
$$\frac{1}{16}$$
Sent to Jail (10)
$$\frac{1}{16}$$
Sent to the closest Utility (12, 18)
$$\frac{1}{16}$$
Sent to St. Charles Place (11)
$$\frac{1}{16}$$
Sent to Illinois Ave. (24)
$$\frac{1}{16}$$
Sent to Boardwalk (39)
$$\frac{1}{16}$$
Sent back 3 spaces

Alter the code to follow the above probabilities when you land on the appropriate squares.

3. User Friendly Printing: The printout that you provided above was not very user friendly. It didn't even write out the names of the squares! Add code to your program so it outputs the name of the square, and its associated probability.

The assignment will be graded on the following requirements according to the course’s programming assignment rubric.

Functionality (75%): A functional program will:

• Represent the monopoly board with a Python list.
• Keep track of the users position on the board.
• Generate a standard Monopoly dice roll (2d6), until the player completes 1000 trips around the board.
• Increment a counter for each square the player lands on
• Print the probabilities for each square on the board.

Style (25%): A program with good style will:

• include a header comment signifying the authors of the file,
• avoid magic numbers (literal primitive numbers),
• use meaningful names for variables and functions,
• have statements that are small (80 characters or less including leading space) and do one thing,
• have functions that are small (40 lines or less including comments) and do one thing
• have a comment above functions that includes the purpose, the pre-conditions, and the post-conditions of the function.
• have spaces after commas in argument lists and spaces on both sides of binary operators (=, +, -, *, etc.).

Space Invaders is an early shooting game that was so popular that the pixelated images of the alien invaders have become symbols of 80's nostalgia and retro gaming. In Space Invaders you control a mobile cannon that can shoot aliens that are invading Earth.

### Details

Create a simplified version of the game Space Invaders like the following:

1. The cannon should be at the bottom of the screen and able to move left or right in response to the arrow keys being pressed.
2. The cannon should shoot a single missile straight up when the space key is pressed.
3. Aliens should start at a random position at the top of the screen and move straight down.
4. Periodically more aliens should be created. It should be possible for there to be more than on alien on the screen.
5. If an alien reaches the bottom of the screen a game over message should be displayed.
6. If the missile hits an alien, the alien should disappear.

### Extra

Make the game more like the original. Add multiple types of enemies with different behaviors like moving and shooting.

The assignment will be graded on the following requirements according to the course’s programming assignment rubric.

Functionality (75%): A functional program will:

• move a cannon laterally with arrow key presses
• shoot missiles straight up with the space key
• have aliens that descend from random locations at the top of the screen
• periodically create more aliens
• end the game if an alien reaches the bottom of the screen
• destroy aliens when they are hit by a missile

Style (25%): A program with good style will:

• include a header comment signifying the authors of the file,
• avoid magic numbers (literal primitive numbers),
• use meaningful names for variables and functions,
• have statements that are small (80 characters or less including leading space) and do one thing, and
• have a comment above functions that includes the purpose, the pre-conditions, and the post-conditions of the function.
• have spaces after commas in argument lists and spaces on both sides of binary operators (=, +, -, *, etc.).

## Submission

Submit your program as a .py file on the course Inquire page before class on Wednesday November 9th.