Question: Several games rely on collecting and exchanging resources for objects worth points. These games are often referred to as resource management games. One famous example
Several games rely on collecting and exchanging resources for objects worth points. These games
are often referred to as "resource management games." One famous example is Settlers of Catan,
where players are challenged to build settlements on an island. In this game, players collect five
types of resources in the form of cards:
Brick,
Wood,
Ore,
Wheat, and
Sheep.
With these resources, players can purchase the following items:
You will write code that attempts to calculate the amount victory points a person can achieve with a certain number of resources.
The end user is asked to input the resource cards they have available and the program returns the points for the number of resource cards and possibly, any left over resources.
It should effectively utilize lists, for loops, and conditionals to provide one conversion from resources to victory points.
DESCRIPTION OF FUNCTIONS
Write a function called subtractlists which takes in two lists as parameters and returns a list. This function will
check that the lists are the same size and can be subtracted, then
subtract the second list provided from the first.
It will return the list that reflects this difference.
Write a function called addlists which takes in two lists as parameters and returns a list. The function will
check that the lists are the same size and can be added, then
add the two lists together elementbyelemebt.
It will return the list that reflects the sum.
Write a function called isnonnegative, which takes in a list as a parameter and returns a boolean value. The function will verify that each entry is not less than If it finds an entry is less than it will return False. If it does not, it will return True. Hint: Test this function with lots of different casesmany new programmers set this up incorrectly.
Write a function called tabulateresources, which takes in one list that is assumed to hold the names of the resources as strings and returns a list with the numbers of each resource. Within the function,
prompt the user to enter how many of these resource cards are held.
Store the resulting counts in another list.
Return the list with resource counts.
Write a function called vpointcountCatan which takes in one list of resource counts and returns a float reflecting the total victory points possible according to the table provided. The function should print how many of each item eg cities, roads, etc should be purchased with the resources. Within this function, expect to define four lists:
A list tracking the number of each item that can be purchased.
A list of the items as strings, egCity "Settlement", "Development Card", "Road"
A list of lists, where each entry is a list of the resources required in the correct order! eg
A list of the victory points for each item, eg
The idea of this function will be to go through the items, subtract the amount of resources needed to purchase the maximal amount starting from the highest points cities to the lowest points roads Once you know the number to purchase, store and print that. Convert each count to points and return the points. Expect to use some or all of the previous functions written.
Finally, copy and past the following function, called exchange, into your file. You may have to fix the tabs When you test the final product, call this function to run your code.
def exchange:
finds the points for the number of resource cards in Settlers of Catan without exchanges"""
rescounts
resources Brick "Wood", "Ore", "Wheat", "Sheep"
rescounts tabulateresourcesresources
points vpointcountCatanrescounts
printExpected points will be points
printLeft over resources are..."
for i in rangelenresources:
if rescountsi:
printresourcesi rescountsi
PART
It is important to note that four resource cards of any kind can be converted into card another resource. For example, sheep wood. Write an extra function that performs these exchanges to increase the total number of victory points earned.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
