Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CODE ALL OF TASK 1 HERE UNDER THE FILE NAME property.py class Property: def __init__(self, property_name: str, property_cost: int, hotel_cost: int, rent_price: int, colour_group: str)

image text in transcribedimage text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

CODE ALL OF TASK 1 HERE UNDER THE FILE NAME "property.py"

class Property:

def __init__(self, property_name: str, property_cost: int, hotel_cost: int, rent_price: int, colour_group: str) -> None: raise NotImplementedError

def get_property_name(self) -> str: raise NotImplementedError

def get_property_cost(self) -> int: raise NotImplementedError

def get_hotel_cost(self) -> int: raise NotImplementedError

def get_hotels_built(self) -> int: raise NotImplementedError

def get_rent_price(self) -> int: raise NotImplementedError

def get_colour_group(self) -> str: raise NotImplementedError

def get_owner(self) -> object: raise NotImplementedError

def get_location(self) -> tuple: raise NotImplementedError

def set_owner(self, owner) -> None: raise NotImplementedError

def set_rent_price(self, rent_price: int) -> None: raise NotImplementedError

def set_location(self, location: tuple) -> None: raise NotImplementedError

def construct_hotel(self) -> None: raise NotImplementedError

def __str__(self) -> str: raise NotImplementedError

def __repr__(self) -> str: return self.__str__()

if __name__ == "__main__": # Test your function here # property1 = Property("States Avenue", 50, 60, 20, "Yellow") # print(property1) # property1.construct_hotel() pass

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

FOR TASK 2:

1.

USE THE WORKING property.py CODE FROM TASK 1 ABOVE.

2.

USE THE BELOW AS A REFERENCE AND DO NOT EDIT. REGARD IT AS A FILE CALLED "property_csv_data_a.py"

delimiter = '/' csv_data = [ "key/property_name/property_cost/hotel_cost/rent_price/colour_group", "atlantic_ave/Atlantic Avenue/100/110/45/Blue", "med_ave/Mediterranean Avenue/20/30/5/Blue", "boulevard_ave/Oriental Avenue/180/190/85/Blue", "penn_ave/Pennsylvania Avenue/140/150/65/Blue", "st_james_place/St. James Place/60/70/25/Blue", "kentucky_ave/Kentucky Avenue/70/80/30/Green", "man_place/Mansfield Place/220/230/110/Green", "marvin_gardens/Marvin Gardens/110/120/50/Green", "oriental_ave/Oriental Avenue/30/40/10/Green", "park_place/Park Place/150/160/70/Green", "vermont_ave/Vermont Avenue/190/200/90/Green", "boardwalk/Boardwalk/160/170/75/Red", "conn_ave/Connecticut Avenue/200/210/95/Red", "indiana_ave/Indiana Avenue/80/90/35/Red", "pacific_ave/Pacific Avenue/120/130/55/Red", "st_charles_place/St. Charles Place/40/50/15/Red", "baltic_ave/Baltic Avenue/170/180/80/Yellow", "illinois_ave/Illinois Avenue/90/100/40/Yellow", "nc_ave/North Carolina Avenue/130/140/60/Yellow", "states_ave/States Avenue/50/60/20/Yellow", "ten_ave/Tennessee Avenue/210/220/100/Yellow"]

3.

USE THE BELOW AS A REFERENCE AND DO NOT EDIT. REGARD IT AS A FILE CALLED "property_csv_data_b.py"

delimiter = '|' csv_data = [ "rent_price|property_cost|hotel_cost|property_name|key|colour_group", "30|40|35|Blueberry Boulevard|blue_blvd|Blue", "40|60|55|elderberries express|elder_exp|Blue", "35|50|40|Pea Flower pavement|pea_pm|Blue", "100|125|110|potato pathway|potato_pw|Blue", "120|190|180|Starflower street|star_st|Blue", "70|65|70|taro trail|taro_tr|Blue", "60|85|70|Avocado Avenue|avo_ave|Green", "45|50|45|brocolli bypass|broco_byp|Green", "40|55|50|cabbage culdesac|cabb_culd|Green", "70|100|80|cucumber crossroad|cucumb_cr|Green", "110|150|130|pandan pavement|pandan_pm|Green", "90|120|110|spinach street|spinach_st|Green", "90|115|120|chilli crossroad|chilli_cr|Red", "100|200|180|doughnut driveway|dough_dr|Red", "50|45|50|passionfruit pavement|passion_pm|Red", "90|85|100|rhubarb roadway|rhubard_rd|Red", "55|70|60|strawberry street|straw_st|Red", "45|60|50|Watermelon walkway|water_wa|Red", "20|40|30|Butter boulevard|butter_blvd|Yellow", "25|40|30|lemon lane|lemon_ln|Yellow", "110|150|135|pineapple pathway|pine_pw|Yellow", "80|100|90|Saffron straits|saffron_st|Yellow", "50|60|55|sundae street|sundae_st|Yellow", "90|130|120|Turmeric trail|turm_tr|Yellow"]

4.

THIS CODE IS USED FOR 2.1 AND SO ON. REGARD THIS AS A FILE UNDER THE NAME "property_generator.py"

from property import Property import random

class PropertyGenerator: def __init__(self) -> None: raise NotImplementedError def csv_to_properties(self, data: str, delimiter: str) -> None: raise NotImplementedError

def property_location_generator(self) -> None: raise NotImplementedError

if __name__ == "__main__": # Test your function here # board_properties = PropertyGenerator() pass

PLEASE CODE THIS IN PYTHON. READ AND UNDERSTAND THE INSTRUCTIONS BEFORE PROCEEDING TO DO THE TASKS.

In this assignment, you will be using the more advanced concepts you've learned to build a text-based board game inspired by Monopoly named PyPoly. To win Monopoly, players eliminate opponents by forcing them into bankruptcy. In PyPoly however, the player's goal is to be the first one to purchase a certain target number of properties of the same colour group and build at least one hotel in each of those properties. Additionally, players would be able to choose one specific move trait that determines how they move around the game board (i.e. perpendicularly, diagonally or in an L-shape). The PyPoly's game board will be an nn collection of grids where n is an arbitrary integer. - At the start of the game, all players will be randomly stationed on the board. - Every player will start with a fund of $150. - Players will move to one valid position at each turn (depending on their chosen move trait). - The grid in the board will be assigned with properties and there will be at least 4 reward or penalty chance assigned grids. - If the player lands on a property assigned grid, they can choose to either purchase or pass the property. - A (non-AI) player should not know what property is contained in a grid that has not been visited yet. - Each property will be a part of a colour group (either Blue, Green, Red or Yellow). - If the player lands on a chance assigned grid, they will either face a reduction or addition of funds. - If a player lands on a property that is previously purchased by another player, the player would have to pay a pass-through rent to the owner. For every hotel built on that property, the rent amount will increase by 20%. - A play may choose to sell one of their properties and relinquish ownership if they choose to. - The first player who purchases a target number of properties of the same colour group, and builds at least 1 hotel on each property, wins the game. In this assignment you'll be creating a command-line version of the above game. You'll start off by building out each piece individually and merge your solutions into one Python file that can be executed through Command Prompt or Terminal to play. Create a Property class to be a blueprint for all of the properties that will soon populate the PyPoly board. 1.1 Property Attributes Property will need the following class variable: - ORIGINAL_OWNER string to denote the original owner of the specific property, "Bank" . - COLOUR_GROUPS list to denote the colour_groups, ["Blue", "Green", "Red", "Yellow"] Property will need the following instance variables: - property_name string to denote the name of the property. The first letter of each word must be capitalised. - property_cost integer to denote how much money is needed to purchase a specific property. - hotel_cost integer to denote how much money is needed to build a hotel on a property. - rent_price integer to denote how much should be paid to the owner if a player lands on a purchased property. - colour_group string to denote which colour group a property is part of. - hotels_built integer to denote how many hotels are already built on a property. It is initialised as . - location tuple to denote the grid location of the property on the board. It is initialised as (None, None). - owner to denote who purchased the specific property. It is initially set to the class variable ORIGINAL_OWNER and will eventually be replaced by a Player instance. Do not add any more instance variables than the 8 above. 1.2 General Property Class: Simple Methods This class requires the following methods that will allow us to interact with the values of a property's attributes: - Eight methods where each method will return the value of a specific instance variable. Each method should use the following naming convention 'get_nameofthevariable' where nameofthevariable is the name of the instance variable. - Three methods where each method will set the value of a specific instance variable, namely for: owner, location and rent_price. Each method should use the following naming convention 'set_nameofthevariable' where nameofthevariable is the name of the instance variable. i Please access or set all instance variables using these getter and setter methods instead of accessing them directly. 1.3 Construct Hotel Create a method construct_hotel that will check if it is possible to build more hotels on the property. If not, it should print the message The maximum number of hotels have been built on property_name>. Otherwise, it will update hotels_built and print the message hotels have been built on . or the singular equivalent. Players can only build on a property twice. Example output: propertyl = Property("States Avenue", 50, 60, 20, "Yellow") propertyl.construct_hotel() 1 hotel has been built on States Avenue. propertyl.construct_hotel() 2 hotels have been built on States Avenue. propertyl.construct_hotel() The maximum number of hotels have been built on States Avenue. 1.4 String Representation of Objects You will need the following magic methods defined for this class: - __str__ to use print() or str() on our custom objects. Implement in the Property class by returning the string property_name. - _ _repr__ should simply call self.__str__(), allows you to see the same string of your property rather than 0x000001931 DB72890> in the error log or when printing the property directly. Example output: propertyz = Property("doughnut driveway", 70, 60, 50, "Red") print(propertyz) Doughnut Driveway Task 2: Generate Properties Based on CSV Data Create a PropertyGenerator class that will help us generate properties based on CSV data and assign those properties random grid locations on the PyPoly board. You will need to implement the following methods in the PropertyGenerator class: - csv_to_properties which reads a property CSV data to create instances of the class Property. - property_locations_generator which will assign a random location to each instance created in csv_to_properties. Note that there are 3 files provided in this task: - property_csv_data_a.py and property_cs__data_b.py are modules containing property data. Do not edit them. - property_generator.py is the main file. 2.1 PropertyGenerator Attributes PropertyGenerator will need the following instance variables: - properties list containing all the property instances. It is initialised as an empty list. - property_locations dictionary where the keys are the grid locations i.e. (x,y) coordinates of each property instance, and the corresponding values are the property instances. It is initialised as an empty dictionary. - number_of_locations integer to denote the total number of grid locations on the board. It is initialised as . Do not add any more instance variables than the 3 above. 2.2 CSV to Properties There will be two sets of example CSV property data provided, each of which needs to be searched through to retrieve the data that we will use to set up the PyPoly properties. - First import both sets of CSV data modules. - Write a method called csv_to_properties that will take in the delimiter string and data list from one of those modules. - This method should work on any CSV data modules that follows the assumptions below. - Create a Property instance for every row in data. - Use the column data fields property_name, property_cost, hotel_cost, rent_price, colour_group to read and parse the data necessary for the creation of Property instances. You can assume these columns will always exist. - You can assume that the header will always contain those column names. - You can assume that the number of rows will always be a multiple of four. - You cannot assume that the column order will always be the same. - Finally, store all Property instances in the properties list. 2.3 Generate Property Locations Ultimately, we want to create an nn grid that contains the properties from csv_to_properties and chance grids that will cause a Player to either receive a penalty or reward. Write a method called property_location_generator that does the following: - Determine the number_of_properties by finding the closest square number that could fit at least four chance grids and all the Property instances in properties. - Randomly generate the grid location i.e. (x,y) location coordinate for each property where: - x denotes the property's row index on the board, - y denotes the property's column index on the board. - The unoccupied grids will become the chance grids which are Property instances with either "Penalty" or "Reward" as the property_name, "Bank" as the owner, and the other attributes set to None. Ideally, there should be roughly equal amounts of Penalty/Reward chance grids. - Update the location attribute for every Property instance. - Finally, using the (x,y) coordinate as the keys, store all Property instances in the property_locations dictionary. csv_to_properties and property_location_generator may produce the following random outputs for the property_csv_data_a and property_csv_data_b modules. board_properties = PropertyGenerator () board_properties.csv_to_properties(data, delimiter) board_properties.property_location_generator() print(board_properties.number_of_locations) for key, value in board_properties.property_locations.items ( ): print(key, value.get_property_name()) number, 66=36 Each of the 24 properties and remaining 12 chance grids will be assigned a randomly generated location on the board. 36 (,) Watermelon Walkway (,1) Pineapple Pathway (,2) Reward (,3) Cucumber Crossroad (,4) Spinach Street (,5) Cabbage Culdesac (1,0) Penalty (1,1) Brocolli Bypass (1,2) Starflower Street (1,3) Reward (1,4) Pandan Pavement (1,5) Turmeric Trail (z,0) Pea Flower Pavement (z,1) Penalty (2,2) Passionfruit Pavement (2,3) Avocado Avenue (2,4) Reward (2,5) Reward (3,) Doughnut Driveway (3,1) Reward (3,2) Strawberry Street (3,3) Penalty (3,4) Penalty (3,5) Rhubarb Roadway (4,0) Butter Boulevard (4,1) Penalty (4,2) Lemon Lane (4,3) Potato Pathway (4,4) Chilli Crossroad (4,5) Elderberries Express (5,0) Taro Trail (5,1) Reward (5,2) Sundae Street (5,3) Penalty (5,4) Blueberry Boulevard (5,5) Saffron Straits Example output 2: Note that there are 20 properties in property_csv_data_b. To include at least 4 chance grids, we will need 24 grids minimum, therefore the number_of_properties will be set at the nearest square number, 55=25. Each of the 20 properties and remaining 5 chance grids will be assigned a randomly generated location on the board. 25 (, e) Penalty (,1) Connecticut Avenue (,2) Tennessee Avenue (,3) Boardwalk (,4) Vermont Avenue (1, e) States Avenue (1,1) Marvin Gardens (1,2) Atlantic Avenue (1,3) Mediterranean Avenue (1,4) Reward (z,) Kentucky Avenue (2,1) St. James Place (z,z) Reward (2,3) North Carolina Avenue (2,4) Boulevard Avenue (3,0) Indiana Avenue (3,1) Penalty (3,2) St. Charles Place (3,3) Park Place (3,4) Pacific Avenue (4,) Illinois Avenue (4,1) Mansfield Place (4, 2) Pennsylvania Avenue (4,3) Baltic Avenue (4,4) Oriental Avenue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

5. Describe the visual representations, or models, of communication

Answered: 1 week ago