Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please code in C language! Please make sure they're no bugs or errors or recycled answers in your code This should be the output: $

Please code in C language! Please make sure they're no bugs or errors or recycled answers in your code

This should be the output:

$ ./monopoly 15 100 100000 id balance 0 67 1 95 2 204 3 244 4 102 5 228 6 0 7 72 8 33 9 0 10 54 11 27 12 76 13 18 14 280 average: 100.000000 max: 280, max/average = 2.800000 after 5 rounds $ ./monopoly 20 100 100000 id balance 0 340 1 200 2 203 3 260 4 74 5 137 6 199 7 68 8 40 9 0 10 39 11 46 12 16 13 137 14 47 15 56 16 28 5 17 15 18 57 19 38 average: 100.000000 max: 340, max/average = 3.400000 after 5 rounds

Here is the starter code:

#include  #include  #include  //There will be m players in an array typedef struct Player { int id; int loc; long balance; } TPlayer; //There will be n properties in an array typedef struct Property { int id; int owner_id; int rent; } TProperty; //TODO //Implement the following function //The player p1 needs to pay the player p2 'amount' of dollars //If p1 has enough balance, the transaction will be successful //Otherwise, p1 will pay all of their balance to p2, and the transaction //is not successful //return 1 if the transaction is successful //Otherwise, return 0 int transaction(TPlayer *p1, TPlayer *p2, int amount) { } //TODO //Finish the following function //If one player cannot pay rent to another player, this function should return 0. //The rest of the players will not get chances to play when this happens int one_round(int m, int n, TPlayer p[], TProperty prop[]) { for(int i = 0; i  max) max = p[i].balance; } printf("average: %f max: %ld, max/average = %lf ", (double)sum/m, max, (double)max*m/sum); } //max_rounds is needed because the game may never finish void monopoly(int m, int n, TPlayer p[], TProperty prop[], int max_rounds) { srand(12345); int rounds = 1; while(one_round(m, n, p, prop) && rounds = 13); assert(m >= 1); assert(rounds >= 1); int rounds = atoi(argv[3]); TPlayer p[m]; TProperty prop[n]; for(int i = 0; i  

image text in transcribed

Exercise 2. (50 points) Monopoly 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 0 and goes to n1 in a clockwise direction. Then the index goes back to 0 , 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 0 , and players take turns according to the increasing order of their id. When it is a player's 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 6 -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 1 to n between the first and final properties. Whenever a player goes back to or passes over property 0,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 0m1, loc is in the range 0n1, and balance represents the wealth accumulated by the user. Similarly, to describe a property, we use the following structure

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

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

Find y'. y= |x + X (x) (x) X 1 02x+ 2x 1 O 2x + 1/3 Ex 2x +

Answered: 1 week ago