Question: Exercise 2 . ( 5 0 points ) Monopoly Inthisexercise,wewill implementasimplifiedMonopolygame.Wewill seewhetherandwhenpure luck cancreateextremeinequalityinwealth. OurMonopolygamehastwomajorcomponents: anarrayofplayersandanarrayofproperties.Thenumber ofplayersismandthenumberofpropertiesisn. Thenpropertiesarearrangedinacircular fashion. The indexof thepropertiesstarts from 0 andgoesto
ExercisepointsMonopoly
Inthisexercise,wewill implementasimplifiedMonopolygame.Wewill seewhetherandwhenpure luck
cancreateextremeinequalityinwealth.
OurMonopolygamehastwomajorcomponents: anarrayofplayersandanarrayofproperties.Thenumber
ofplayersismandthenumberofpropertiesisn.
Thenpropertiesarearrangedinacircular fashion. The indexof thepropertiesstarts fromandgoesto
ninaclockwisedirection.Thentheindexgoesbackto thestartingpoint.
Atthebeginningof thegame,all theplayershavendollarsastheir initialbalance.All theplayerstartat
propertyandplayerstaketurnsaccordingtotheincreasingorderof their idWhenit isaplayersturn
theplayertossestwodicetodeterminethenumberofstepstheyneedtomoveinaclockwisedirection.The
facevalueofthetwosideddicearesummedtofindthenumberofsteps.Theplayermovesthisnumberof
stepsandlandsonthecorrespondingproperty. Ifthispropertyisownedbysomeoneotherthanthisplayer,
thisplayerneedstopayrenttotheowner.Otherwise, ifthispropertyhasnoowneryet, itwillbeownedby
thisplayer.Rent increaselinearlyfromtonbetweenthefirstandfinalproperties.
Wheneveraplayergoesbacktoorpassesoverpropertyndollarswillbeawardedtotheplayer.
Thegameendswhenaplayer is requiredtopaymoremoneythantheyown. Whenthishappens, that
playerpaysallof theirmoneytotheplayerwhoownsthepropertytheyjust landedon.Attheendof the
game,wewillestimatetheinequalityoftheplayersasthehighestwealthdividedbytheaveragewealth
Todescribeaplayer,weneedtousethestructure
typedefstructPlayer
intid;
intloc;
longbalance;
TPlayer;
Here, id is inthe rangem loc is inthe rangen andbalancerepresents thewealth
accumulatedbytheuser.
Similarly, todescribeaproperty,weusethefollowingstructure
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;
introunds;
The followinglineofcodeisneededforcorrectoutput
printresultmp;
printfafterdrounds
rounds;
Belowareoutputsfromafewsampleruns.Wecanusetheseoutputstocheckourcode.
$monopoly
id balance
average:max:maxaverage
afterrounds
$monopoly
id balance
average:max:maxaverage
afterrounds
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
