Does not run the code or or it runs incorrectly. And

does not make .cs files only mode4_connectioncount.csv.

Where is the mistake?

Code:#include <stdio.h> #include <math.h> #include <stdlib.h> #include <time.h> #include <stdbool.h> enum strategy { DOVE, HAWK }; struct player { enum strategy strat; struct player** neighbors; int neighborCount; }; double GetValue(struct player* plyr, double prize, double hawkWinningMultiplier) { int value = 0; for (int i = 0; i < plyr->neighborCount; i++) { if (plyr->strat == DOVE) { if (plyr->neighbors[i]->strat == HAWK) { } else { value += prize; } } else { if (plyr->neighbors[i]->strat == HAWK) { } else { value += hawkWinningMultiplier * prize; } } } return value; } bool AddConnection(struct player* plyr1, struct player* plyr2) { for (int i = 0; i < plyr1->neighborCount; i++) { if (plyr1->neighbors[i] == plyr2) { return false; } } struct player** tmp; tmp = (struct player*)malloc(sizeof(struct player) * (plyr1->neighborCount + 1)); for (int i = 0; i < plyr1->neighborCount; i++) { tmp[i] = (plyr1->neighbors[i]); } tmp[plyr1->neighborCount] = plyr2; plyr1->neighborCount++; plyr1->neighbors = (struct player**)realloc(plyr1->neighbors, sizeof(struct player*) * plyr1->neighborCount); for (int i = 0; i < plyr1->neighborCount; i++) { plyr1->neighbors[i] = tmp[i]; } free(tmp); tmp = (struct player*)malloc(sizeof(struct player) * (plyr2->neighborCount + 1)); for (int i = 0; i < plyr2->neighborCount; i++) { tmp[i] = (plyr2->neighbors[i]); } tmp[plyr2->neighborCount] = plyr1; plyr2->neighborCount++; plyr2->neighbors = (struct player**)realloc(plyr2->neighbors, sizeof(struct player*) * plyr2->neighborCount); for (int i = 0; i < plyr2->neighborCount; i++) { plyr2->neighbors[i] = tmp[i]; } free(tmp); return true; } struct player CreatePlayer(enum strategy str) { struct player plyr; plyr.neighborCount = 0; plyr.neighbors = malloc(0); plyr.strat = str; return plyr; } bool getBoolWithProbability(double probability) { double random_value; random_value = (double)rand() / RAND_MAX; return (random_value < probability); } void PlayPlayer(struct player* playingPlayer, double prize, double hawkWinningMultiplier) { int index = rand() % playingPlayer->neighborCount; struct player* other = playingPlayer->neighbors[index]; if (GetValue(playingPlayer, prize, hawkWinningMultiplier) < GetValue(other, prize, hawkWinningMultiplier) && playingPlayer->strat != other->strat) { double delta_p = GetValue(other, prize, hawkWinningMultiplier) - GetValue(playingPlayer, prize, hawkWinningMultiplier); double p_max = fmax(playingPlayer->neighborCount, other->neighborCount); bool result = getBoolWithProbability(exp(-(delta_p / p_max))); if (result) { if (playingPlayer->strat == HAWK) { playingPlayer->strat = DOVE; } else { playingPlayer->strat = HAWK; } } } } double game(double prize, int gameCount, double hawkWinningMultiplier, int playerCount) { struct player* players = (struct player*)malloc(sizeof(struct player) * playerCount); for (int i = 0; i < playerCount; i++) { enum strategy strat = HAWK; if (getBoolWithProbability(0.5)) { strat = DOVE; } players[i] = CreatePlayer(strat); } AddConnection(&players[0], &players[1]); AddConnection(&players[2], &players[1]); AddConnection(&players[0], &players[2]); int connectionCount = 6; for (int i = 3; i < playerCount; i++) { int index = rand() % connectionCount; for (int j = 0; j < playerCount; j++) { index -= players[j].neighborCount; if (index <= 0) { AddConnection(&players[i], &players[j]); connectionCount += 2; } } } int doves = 0; int hawks = 0; int maxConnections = 0; for (int i = 0; i < playerCount; i++) { if (players[i].strat == HAWK) { hawks += 1; } else { doves += 1; } if (players[i].neighborCount > maxConnections) { maxConnections = players[i].neighborCount; } } int* connections = (int*)malloc(sizeof(int) * maxConnections); //connection[x] is the count of players with x connections for (int i = 0; i < maxConnections; i++) { connections[i] = 0; } printf("START: Doves: %i, hawks: %i \n", doves, hawks); for (int i = 0; i < gameCount; i++) { int index = rand() % playerCount; PlayPlayer(&players[index], prize, hawkWinningMultiplier); } doves = 0; hawks = 0; for (int i = 0; i < playerCount; i++) { if (players[i].strat == HAWK) { hawks += 1; } else { doves += 1; } connections[players[i].neighborCount] += 1; } printf("END: Doves: %i, hawks: %i \n", doves, hawks); FILE* fp; fp = fopen("mode4_connectioncount.csv", "w"); fprintf(fp, "connection count; number of players;\n"); for (int i = 0; i < maxConnections; i++) { fprintf(fp, "%i; %i;\n", i, connections[i]); } fclose(fp); return ((double)doves) / (doves + hawks); } void testGameCount(double prize, int gameCount, double hawkMultiplier, int playerCount, int repetitionCount) { double* averages = (double*)malloc(gameCount * sizeof(double)); for (int i = 0; i < gameCount; i++) { double result = 0; for (int j = 0; j < repetitionCount; j++) { result += game(prize, i + 1, hawkMultiplier, playerCount); } result = result / repetitionCount; result = result / repetitionCount; averages[i] = result; } FILE* fp; char* buf[30]; snprintf(buf, 30, "mode%i_gameCountTest.csv"); fp = fopen(buf, "w"); fprintf(fp, "game count; percentage of doves;\n"); for (int i = 0; i < gameCount; i++) { fprintf(fp, "%i; %f;\n", i + 1, averages[i]); } fclose(fp); } void testPrizeAmount(double prize, int gameCount, double hawkMultiplier, int playerCount, int repetitionCount) { double* averages = (double*)malloc(gameCount * sizeof(double)); int x = 0; for (double i = 0; i < prize; i += 0.1, x++) { double result = 0; for (int j = 0; j < repetitionCount; j++) { result += game(i, gameCount, hawkMultiplier, playerCount); } result = result / repetitionCount; result = result / repetitionCount; averages[x] = result; } FILE* fp; char* buf[30]; snprintf(buf, 30, "mode%i_PrizeAmountTest.csv"); fp = fopen(buf, "w"); fprintf(fp, "prize amount; percentage of doves;\n"); x = 0; for (double i = 0; i < prize; i += 0.1, x++) { fprintf(fp, "%i; %f;\n", (double)i / 10, averages[x]); } fclose(fp); } void testPlayerCount(double prize, int gameCount, double hawkMultiplier, int playerCount, int repetitionCount) { double* averages = (double*)malloc((playerCount - 1) * sizeof(double)); for (int i = 1; i < playerCount; i++) { double result = 0; for (int j = 0; j < repetitionCount; j++) { result += game(prize, gameCount, hawkMultiplier, i); } result = result / repetitionCount; result = result / repetitionCount; averages[i] = result; } FILE* fp; char* buf[30]; snprintf(buf, 30, "mode%i_playerCountTest.csv"); fp = fopen(buf, "w"); //Saving data to file fprintf(fp, "player count; percentage of doves;\n"); for (int i = 0; i < playerCount; i++) { fprintf(fp, "%i; %f;\n", i + 1, averages[i]); } fclose(fp); } int main() { const int repetitionCount = 20; double prize = 1.0; int gameCount = 50; double hawkMultiplier = 1.5; int playerCount = 50; testGameCount(prize, gameCount, hawkMultiplier, playerCount, repetitionCount); testPrizeAmount(prize, gameCount, hawkMultiplier, playerCount, repetitionCount); testPlayerCount(prize, gameCount, hawkMultiplier, playerCount, repetitionCount); return 0; }