Question: In this exercise, we will implement a simplified Monopoly game. We will see whether and when pure luck can create extreme inequality in wealth. Our
In this exercise, we will implement a simplified Monopoly game. We will see whether and when pure luck
can create extreme inequality in wealth.
Our Monopoly game has two major components: an array of players and an array of properties. The number
of players is m and the number of properties is n
The n properties are arranged in a circular fashion. The index of the properties starts from and goes to
n in a clockwise direction. Then the index goes back to the starting point.
At the beginning of the game, all the players have n dollars as their initial balance. All the player start at
property and players take turns according to the increasing order of their id When it is a players turn,
the player tosses two dice to determine the number of steps they need to move in a clockwise direction. The
face value of the two sided dice are summed to find the number of steps. The player moves this number of
steps and lands on the corresponding property. If this property is owned by someone other than this player,
this player needs to pay rent to the owner. Otherwise, if this property has no owner yet, it will be owned by
this player. Rent increase linearly from to n between the first and final properties.
Whenever a player goes back to or passes over property n dollars will be awarded to the player.
The game ends when a player is required to pay more money than they own. When this happens, that
player pays all of their money to the player who owns the property they just landed on At the end of the
game, we will estimate the inequality of the players as the highest wealth divided by the average wealth.
To describe a player, we need to use the structure
typedef struct Player
int id;
int loc;
long balance;
TPlayer;
Here, id is in the range m loc is in the range n and balance represents the wealth
accumulated by the user.
Similarly, to describe a property, we use the following structure
typedef struct Property
int id;
int ownerid;
int rent;
TProperty;
Here, id is in the range n owner id is in the range m and rent is the rent of the property.
Below is the main function of the program; note how we use the command line arguments. Here m is
the number of players, n is the number of properties, and rounds is the maximum rounds of game in case
the game does not end.
int mainint argc, char argv
ifargc
printfUsage: s m n rounds
argv;
return ;
int m atoiargv;
int n atoiargv;
int rounds atoiargv;
TPlayer pm;
TProperty propn;
forint i ; i n; i
propiid i;
propiownerid ;
propirent i ;
forint j ; j m; j
pjid j;
pjloc ;
pjbalance n;
monopolym n p prop, rounds;
return ;
Note how we initialize the player array pm and the property array propn The owner id for each property
is set to since, at the beginning, it is not owned by any player. We use instead of because id is
the id for the first player.
We need to implement the following function.
Implement the following function
void monopolyint m int n TPlayer p TProperty prop int maxrounds
srand;
int rounds ;
The following line of code is needed for correct output
printresultm p;
printfafter d rounds
rounds;
Below are outputs from a few sample runs. We can use these outputs to check our code.
$ monopoly
id balance
average: max: maxaverage
after rounds
$ monopoly
id balance
average: max: maxaverage
after rounds#include stdioh
#include stdlibh
#include ;
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
