Each street in Monopoly is comprised of 2 or 3 different properties.
When a user upgrades a street, it will build 1 of 3 buildings on the appropriate property.
House – least valuable, will build this by default, max 16 per property.
Hotel – costs 3 houses to build. Max 8 per property.
Sky scraper – most valuable, costs 2 hotels to build, max 1 per property.
Each type of building needs to be spread evenly. For example if there’s 2 properties, the order of upgrades would be:
House on property 1
House on property 2
House on property 1
House on property 2
House on property 1
House on property 2
Hotel on property 1 (also delete 3 houses)
Hotel on property 2 (also delete 3 houses)
House on property 1
The only time there would be more than 3 houses on a property is after the skyscrapers and hotels are both maxed out, then the houses would stack up until 16 on each property.
I need a function that will calculate this. The parameters of this function are numOfProperties, numOfSkyScrapers, numOfHotels, numOfHouses and it needs to output which building should be next.
This function cannot use looping. I think the mod operator would be useful.
My code below works when there is 1 property. But with 2 properties, upgrade 8 is a house when it should be a hotel. It’s because after the first hotel upgrade, it deletes that properties 3 houses, so the total number is 3 again and builds another house.
I’m not sure how I can make this dynamic and work for all amount of properties
def next_building(num_properties, num_houses, num_hotels, num_skyscrapers):
# Maximum limits per property
max_houses_per_property = 16
max_hotels_per_property = 8
max_skyscrapers_per_property = 1
# Conversion ratios
houses_per_hotel = 3
hotels_per_skyscraper = 2
# Calculate the number of buildings per property
houses_per_property = num_houses // num_properties
hotels_per_property = num_hotels // num_properties
skyscrapers_per_property = num_skyscrapers // num_properties
# Calculate remainders to help balance the properties
houses_remainder = num_houses % num_properties
hotels_remainder = num_hotels % num_properties
skyscrapers_remainder = num_skyscrapers % num_properties
# Determine the next building to construct
if num_hotels >= hotels_per_skyscraper and (skyscrapers_per_property < max_skyscrapers_per_property):
# Check if there are enough hotels for the next skyscraper
return "skyscraper"
if num_houses >= houses_per_hotel and (hotels_per_property < max_hotels_per_property):
# Check if there are enough houses for the next hotel
return "hotel"
if houses_per_property < max_houses_per_property:
return "house"
return "No building needed"