Project 1 – Pyopoly

Value: 100 points

This assignment falls under the standard cmsc201 academic integrity policy.  This means you should not discuss/show/copy/distribute your solutions, your code or your main ideas for the solutions to any other student.  Also, you should not post these problems on any forum, internet solutions website, etc. 

“””

File:    FILENAME.py

Author:  YOUR NAME

Date:    THE DATE

Section: YOUR DISCUSSION SECTION NUMBER

E-mail:  YOUR_EMAIL@umbc.edu

Description:

  DESCRIPTION OF WHAT THE PROGRAM DOES

    “””

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. 

 

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. 

 

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. “xxxxx\nxxxxx” 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. 
  5. 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. 
  6. 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. 

 

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:

  1. Go into settings (CTRL + ALT + S) on windows.
  2. Click on Project Structure, which should take you to a directory tree.
  3. Click on the directory where you have your code and click the blue source button, add it as a source directory. 
  4. 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 here

  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.
      1. 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:

  • 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).
    • 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]

  • Constants in mathematical formulas can either be made into official constants or kept in a formula. 
  • Previously checked coding standards involving:
    • snake_case_variable_names
    • CAPITAL_SNAKE_CASE_CONSTANT_NAMES
    • 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 type.
  • 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
    • list.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:

  1. 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):

  1. Within your main, you should call this function with the constants at the top of the program, and the file name for the map.
    1. For testing, you can always make the map-file an input statement.
  2. The function take_turn should be something like:
                          def take_turn(player, players, board):
    1. You are permitted to modify the arguments of the function, these are just the arguments that I used in my code. 
    1. 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. 
  3. You should create a function:
                          def format_display(players, board):
    1. The purpose of this function is to format the output strings for display to the board. 
    1. You need a string of the format “xxxxx\nxxxxx” which means five wildcard characters, a new line and then five more characters. 
    1. You are permitted to use ljust(5) to add padding spaces to the partial strings.
    1. 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. 
  4. 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)

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 .

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. 

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. 

RequirementPoints (appx)
Setting up players so that they can play the game, have the starting money, etc. 5
Getting property abbreviations to output on the board5
Getting the players positions to output correctly, players move correctly on the board15
Getting Player Info10
Getting Property Info15
Buying Property15
Charging correct rents15
Building the Buildings10
Coding Standards, Documentation, Comments, Overall Correctness10
Research Paper 101
Calculate your paper price
Pages (550 words)
Approximate price: -

Reasons to trust Research Paper 101

On Time Delivery

We pride ourselves in meeting the deadlines of our customers. We take your order, assign a writer but allow some more time for ourselves to edit the paper before delivering to you. You are guaranteed a flawless paper on a timely manner...

24x7 Customer Live Support

Our team at Research Paper 101 is committed to handling your paper according to the specfications and are available 24*7 for communication. Whenever you need a quick help, you can talk to our writers via the system messaging or contact support via live chat and we will deliver your message instantly.

Experienced Subject Experts

Online Experts from Research Paper 101 are qualified both academically and in their experiences. Many are Masters and Phd holders and therefore, are qualified to handle complex assignments that require critical thinking and analyses...

Customer Satisfaction

We offer dissertation papers as per students’ wishes. We also help craft out the best topics and design concept papers. By ordering with us, you are guaranteed of defending and making through those hard faced professors in the defense panel!

100% Plagiarism Free

We at Research Paper 101 take plagiarism as a serious offence. From the start, we train our writers to write all their papers from scratch. We also check if the papers have been cited appropriately. Our website also has a tool designed to check for plagiarism that has been made erroniusly. In essense, the paper you get will be 100% legit...

Affordable Prices

We understand that being a student is very challenging, some students balance between work and studies in order to survive. We therefore offer pocket friendly rates that are very competitive in the market.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.

error: