Order Now

Write a game called Pyopoly, which is a very simplified version of Monopoly. 

Project General Description

 

In this project you will write a game called Pyopoly, which is a very simplified version of Monopoly.

 

In this game, you’ll create two players, and have them traverse around a board until one of them goes “insolvent,” i.e. has no money left.  Then the other player will win.

 

You are going to be locked into a game of financial-mortal-combat for the dominance of UMBC’s campus.

 

Write a game called Pyopoly, which is a very simplified version of Monopoly.

Rules of the Game

  1. First you must create the characters for the game.
    1. Each character should have a name, and a symbol, which is a single capital letter.
    2. There are at most two players for the game (a single player game can be used for testing).
  2. Starting funds should be 1500 Retriever Ducats.  (It should be set in a constant so that you can modify it for testing purposes).
  3. Your game sequence should be the following:
    1. Have the player roll two six sided dice (using random.randint).  Remember that randint(1, 12) will produce a uniform distribution, but rolling two dice does not produce a uniform distribution, you should use randint(1, 6) twice and add the result.
    2. Move the player that number of spaces, equal to the roll results.
    3. If the property they land on has price -1, it is unpurchasable.
    4. If the property has price bigger than or equal to zero, it is purchasable.
      1. If the property is owned by someone else, pay them the rent required.
      2. If the property is not owned, it can be purchased by the person who landed on the space.
    5. If the player owns the property they can pay the building cost to build a building on the land.  If they do so, the rent charged to the other player when they land on it is the building-rent cost.
    6. A player cannot sell properties back to the bank, cannot mortgage the properties, and cannot trade them to the other player. (Unlike in real monopoly.)
    7. After the player has decided whether to buy a property on which they land or paid rent to its owner, they can choose to build the building for any land they own.
    8. The player then chooses to end their turn, and it becomes the other player’s turn.
    9. If at any point, a player is required to pay more money than they have, they become insolvent, and lose the game.  Since only two players are allowed, the game should end.
    10. Even if a player has properties with value greater than the debt, they still become insolvent.
    11. A player does not need to have all of the properties in a set to build the building for any particular property.  As soon as the property is owned, the building can be constructed.
  4. If a player passes the start position (0) then they get the pass-go amount of money, 200 by default, but this should be a constant so that it can be modified for testing.
  5. Spaces with price -1 cannot be bought but also have no effect, so you pay nothing for landing on them and get nothing in return.

 

 

 

 

Write a game called Pyopoly, which is a very simplified version of Monopoly.

 

Implementation Details

You are required to implement the project following the guidelines here.

When your player enters their turn you should:

  1. Show them their roll.
    1. Remember to use randint(1, 6) + randint(1, 6) to get the roll.
    2. Move their character around the board.
    3. If they pass go, give them the PASS_GO_AMOUNT (or whatever you name your constant).
  2. Show them the board.  I have written a function for you to use:
    1. The function:

def display_board(the_board):

Has been written for your convenience.  It will take any board which has a multiple of four size, so that it can be a square.

 

It expects a parameter which is a list of strings.

    1. The strings must be of the following form:
      1. “xxxxxnxxxxx” where x can be anything, but the n must be at position 5, and the string must be 11 characters long, including the new line.
    2. The first line should contain the abbreviation of the position from the map.
    3. The second line should include the symbols of the players at each position.
    4. You are permitted to use the string method ljust(5) in order to pad strings to ensure that each string part is 5 characters long.
  1. Give each player the set of options in a menu form.  The player should be able to select the option either by number or by typing the option.  You are free to make it case insensitive and ignore extra whitespace using s.strip().lower() for a string s.
    1. They must be able to buy the property.  This option should be there even if the property is unbuyable.
    2. Get Property Info – use this to allow the player to get information about properties.
      1. Ask for the property, and you should accept either the abbreviation or the name.
      2. Display the place name, price, owner, if it has the building, and the two amounts of rent that it has.
    3. Get Player Info – use this to get information about players.
      1. First output the player names. Ask the user which player they want to check.
      2. Output the player name, symbol, amount of money
      3. Output the properties that the player owns, along with if the building is built on that property.
    4. Build the Building option – allow the player to select which property they want to build a building on, then put a building on that property.
    5. End the Turn option – The player can end their turn when they select that option. That means they are finished building, getting info, and buying property.
  2. Loading the boards – when loading the boards, use the
    def load_map(map_file_name): function.  The function will return a list of dictionaries of the following form with these keys guaranteed (with example values):

 

“Place”: “Terrace Apartments”,

“Abbrev”: “TerAp”,

“Position”: 1,

“Price”: 60,

“Rent”: 2,

“BuildingRent”: 100,

“Building Cost”: 50

 

There can be other keys in the dictionaries, but they can be ignored.

Write a game called Pyopoly, which is a very simplified version of Monopoly.

Auxiliary File and Allowed Imports

 

You should get the file on the GL server:

/afs/umbc.edu/users/e/r/eric8/pub/cs201/fall20/board_methods.py

 

Use the copy command:

cp /afs/umbc.edu/users/e/r/eric8/pub/cs201/fall20/board_methods.py .

Remember to get the period, otherwise it won’t have a destination.

 

You can then import the proper methods by using:

# put your header here

from sys import argv

from random import randint, seed

from board_methods import load_map, display_board

# possibly a lot more code here.

# this code can be anywhere from right under the imports to right # above if __name__ == ‘__main__’:

if len(argv) >= 2:

seed(argv[1])

A Random Pycharm Note

If/when pycharm underlines your board_methods import in red, then you should add the directory as source:

  • Go into settings (CTRL + ALT + S) on windows.
  • Click on Project Structure, which should take you to a directory tree.
  • Click on the directory where you have your code and click the blue source button, add it as a source directory.
  • Then pyCharm should scan it and recognize the board_methods file instead of underlining it in red.

 

Submission Details

 

Submit the files under the following titles:

(These are case sensitive as usual.  )

submit cmsc201 PROJECT1 pyopoly.py

 

You don’t need to submit board_methods.py, since you should never modify it.

Coding Standards

Coding standards can be found .

  1. At least one inline comment per function explaining something about your code.
  2. Constants above your function definitions, outside of the “if __name__ == ‘__main__’:” block.
    1. A magic value is a string which is outside of a print or input statement, but is used to check a variable, so for instance:
      1. print(first_creature_name, ‘has died in the fight. ‘) does not involve magic values.
      2. However, if my_string == ‘EXIT’: exit is a magic value since it’s being used to compare against variables within your code, so it should be:
        EXIT_STRING = ‘EXIT’

if my_string == EXIT_STRING:

  1. A number is a magic value when it is not 0, 1, and if it is not 2 being used to test parity (even/odd).
  2. A number is magic if it is a position in an array, like my_array[23], where we know that at the 23rd position, there is some special data. Instead it should be
    USERNAME_INDEX = 23

my_array[USERNAME_INDEX]

  1. Constants in mathematical formulas can either be made into official constants or kept in a formula.
  1. Previously checked coding standards involving:
    1. snake_case_variable_names
    2. CAPITAL_SNAKE_CASE_CONSTANT_NAMES
    3. Use of whitespace (2 before and after a function, 1 for readability.)

 

Allowed Built-ins/Methods/etc

 

  • Declaring and assigning variables, ints, floats, bools, strings, lists, dicts.
  • Using +, -, *, /, //, %, **; +=, -=, *=, /=, //=, %=, **= where appropriate
  • Comparisons ==, <=, >=, >, <, !=, in
  • Logical and, or, not
  • if/elif/else, nested if statements
  • Casting int(x), str(x), float(x), (technically bool(x))
  • For loops, both for i and for each
  • While loops
    • sentinel values, boolean flags to terminate while loops
  • Lists, list(), indexing, i.e. my_list[i] or my_list[3]
    • 2d-lists if you want them/need them my_2d[i][j]
    • Append, remove
    • list slicing
  • If you have read this section, then you know the secret word is: createous.
  • String operations, concatenation +, +=, split(), strip(), join(), upper(), lower(), isupper(), islower()
    • string slicing
  • Print, with string formatting, with end= or sep=:
    • ‘{}’.format(var), ‘%d’ % some_int, f-strings
    • Really the point is that we don’t care how you format strings in Python
    • Ord, chr, but you won’t need them this time.
  • Input, again with string formatting in the prompt, casting the returned value.

 

 

  • Dictionaries
    • creation using dict(), or {}, copying using dict(other_dict)
    • .get(value, not_found_value) method
    • accessing, inserting elements, removing elements.
    • Deleting elements from dictionaries using del.
  • Using the functions provided to you in the starter code.
  • Using import with libraries and specific functions as allowed by the project/homework.
  • You may define your own new functions with new parameters
    • Single return values (you must return a single float, bool, string, int, list or dictionary, or None/not return).

 

 

Forbidden Built-ins/Methods/etc

This is not a complete listing, but it includes:

  • break, continue
  • methods outside those permitted within allowed types
    • for instance str.endswith
    • index, list.count, etc.
  • Keywords you definitely don’t need: await, as, assert, async, class, except, finally, global, lambda, nonlocal, raise, try, yield
  • The is keyword is forbidden, not because it’s necessarily bad, but because it doesn’t behave as you might expect (it’s not the same as ==).
  • built in functions: any, all, breakpoint, callable, classmethod, compile, exec, delattr, divmod, enumerate, filter, map, max, min, isinstance, issubclass, iter, locals, oct, next, memoryview, property, repr, reversed, round, set, setattr, sorted, staticmethod, sum, super, type, vars, zip
  • If you have read this section, then you know the secret word is: serendipity.
  • exit() or quit()
  • If something is not on the allowed list, not on this list, then it is probably forbidden.
  • The forbidden list can always be overridden by a particular problem, so if a problem allows something on this list, then it is allowed for that problem.

 

 

Design Overview

Your project should include at least the functions:

 

  • The play_game function should be defined and must take two arguments, starting money, pass_go_money, and the board_file

def play_game(starting_money, pass_go_money, board_file):

  • Within your main, you should call this function with the constants at the top of the program, and the file name for the map.
  • For testing, you can always make the map-file an input statement.
  • The function take_turn should be something like:
    def take_turn(player, players, board):

    • You are permitted to modify the arguments of the function, these are just the arguments that I used in my code.
    • I use these arguments to know who is currently taking their turn, the players in the game, and the board state with all of the properties, etc.
  • You should create a function:
    def format_display(players, board):

    • The purpose of this function is to format the output strings for display to the board.
    • You need a string of the format “xxxxxnxxxxx” which means five wildcard characters, a new line and then five more characters.
    • You are permitted to use ljust(5) to add padding spaces to the partial strings.
    • You can change the function’s parameters but you should keep the name the same, so we can reference the function by name in the project.
  • You should create new functions to help support these functions if you need them.

 

 

 

 

Suggested Design Order

We understand that the first big project can be overwhelming, which is why we’ve provided you with a detailed description of the more important functions.

 

This is the order of development that I would suggest to ensure success:

 

  • Begin by experimenting with the load_map function from the board_methods.py file. Print the results after loading boards, and understand how the format is going to work.
  • Write your format_display function in order to be able to output information onto the board.
  • Work on creating a single player game where the player can move around the board, remembering not to leave the bounds of the board (don’t go to position 44 if the board only has 40 positions, you have to wrap around).
  • Add the second player. Ensure that players alternate turns.
  • Add the get info functionality for the properties.
  • Work on allowing players to buy properties.
  • Get the player info functionality working.
  • Work on getting the rent payments working.
  • Add the ability for a player to lose when they reach negative money.
  • Allow players to buy buildings.
  • Fix up rents to work with buildings if you haven’t already done that.
  • (Test Step) Test your project mercilessly.
  • Fix any bugs you find.
  • Submit your project.
  • Go to (Test Step)

 

Write a game called Pyopoly, which is a very simplified version of Monopoly.

 

 

Sample Project Output

Since this project will probably run for a long time, you can test out all the different sample output for all of the different cases if you copy the pyc file:

 

/afs/umbc.edu/users/e/r/eric8/pub/cs201/fall20/pyopoly.pyc

 

First, navigate to your project 1 directory, which could potentially be home/cmsc201/proj1/ for instance.

 

cp /afs/umbc.edu/users/e/r/eric8/pub/cs201/fall20/pyopoly.pyc .

 

You can then run it like this:

 

python3 pyopoly.pyc 12345 proj1_board1.csv

python3 pyopoly.pyc abcde proj1_board2.csv

 

The general format is:

python3 pyopoly.pyc <seed string> <board csv file>

 

The 12345 represents the seed value that you have to enter at the command line.  You can use any seed value as long as it’s a string without spaces.

 

There are currently two sample boards:

 

/afs/umbc.edu/users/e/r/eric8/pub/cs201/fall20/proj1_board1.csv

/afs/umbc.edu/users/e/r/eric8/pub/cs201/fall20/proj1_board2.csv

 

Copy them using the commands:

cp /afs/umbc.edu/users/e/r/eric8/pub/cs201/fall20/proj1_board1.csv .

cp /afs/umbc.edu/users/e/r/eric8/pub/cs201/fall20/proj1_board2.csv .

Write a game called Pyopoly, which is a very simplified version of Monopoly.

Note: It is likely that if you copy this file off of the GL server and try to run it in windows or on a different version of python3, there will be problems with the pyc file.

 

When you run the project, it should appear like this:

 

linux3[139]% python3 pyopoly.pyc 12345 proj1_board1.csv

First player, what is your name? Eric

First player, what symbol do you want your character to use? E

Second player, what is your name? Jimmy

Second player, what symbol do you want your character to use? J

*******************************************************

*FrPrk*Bio  *MathP*Sond *HTRd *FA   *Meyer*Com  *Sherm*

*     *     *     *     *     *     *     *     *     *

*******************************************************

*RAC  *                                         *Study*

*     *                                         *     *

*******                                         *******

*Phys *                                         *Engin*

*     *                                         *     *

*******                                         *******

*PubPo*                                         *ITE  *

*     *                                         *     *

*******                                         *******

*AdDr *                                         *PerfA*

*     *                                         *     *

*******                                         *******

*PatH *                                         *WlkAv*

*     *                                         *     *

*******                                         *******

*SusH *                                         *AlumH*

*E    *                                         *     *

*******                                         *******

*UniC *                                         *Walkr*

*     *                                         *     *

*******************************************************

*PotH *LB   *EH   *HH   *ChesH*PopAv*HillA*TerAp*GO-HC*

*     *     *     *     *     *     *     *     *J    *

*******************************************************

Eric you have rolled 10

Eric you landed on Susquehanna Hall

 

     1) Buy Property

     2) Get Property Info

     3) Get Player Info

     4) Build a Building

     5) End Turn

At this point you can run my version of the project and see some sample output.

In order to quit, you can use CTRL + C to give you a KeyboardInterrupt, which will terminate the program before the game has ended.

 

Write a game called Pyopoly, which is a very simplified version of Monopoly.

 

Approximate Rubric

I say approximate here to mean that this rubric doesn’t break down specific requirements within each group, and may be modified by a few points here and there, but this should provide you with a good understanding of what we intend the value of each piece of the project implementation to be.

 

Requirement Points (appx)
Setting up players so that they can play the game, have the starting money, etc. 5
Getting property abbreviations to output on the board 5
Getting the players positions to output correctly, players move correctly on the board 15
Getting Player Info 10
Getting Property Info 15
Buying Property 15
Charging correct rents 15
Building the Buildings 10
Coding Standards, Documentation, Comments, Overall Correctness 10

 

 

 

 

 

Order Now

Calculate Your Order Price


Price (USD)
$