Hi,
I'm kind of new at this, but I've looked at the code over and over and can't figure out my problem.
Code:
Code:#include <stdlib.h> #include <stdio.h> /* **Assumes that each player has no more than 10 moves each and that NO player is indifferent to the other player's move (i.e. player1's payoff for making ). **Assumes that all the characters are ints separated by spaces and that the first two ints are non-negative. */ main(){ FILE *file; //Declare file pointer int a, b, c, d, e, f, g, h, i, j, k, m, n, p; //Array indexes //~~~Read in file~~~// int cols, rows; int size = cols*rows; int p1Payoffs[size/2], p2Payoffs[size/2]; file = fopen("prisoners_dilema.txt", "r"); if(file==NULL){ printf("Sorry! The file could not be opened!\n"); } else{ //Find #cols & #rows int fscanf(file, "%d %d", &cols, &rows); //Error check if(size > 100){printf("Sorry! The game is too large. Each player may have 10 or fewer plays.\n"); return;} //Read in player's payoffs for(a=0; a<size*2; a;){ int fscanf(file, "%d %d", &p1Payoffs[a], &p2Payoffs[a]); } } fclose(file); //~~~Find Player's Best Responses~~~// int indexP1[size], indexP2[size]; int p1Counter=0, p2Counter=0; //P1's BRs (columns) for(c=0; c<cols-1; c++){//for each columns for(d=0; d<size-cols; d+cols){//and for each cell in that column if(p1Payoffs[d]>p1Payoffs[d+cols]){indexP1[p1Counter] = d; p1Counter++;} else if(p1Payoffs[d]==p1Payoffs[d+cols]){ indexP1[p1Counter] = d; indexP1[p1Counter+1] = d+cols; p1Counter = p1Counter+2; } } } //P2's BRs (rows) for(e=0; e<rows-1; e++){//for each row for(f=0; f<cols; f++){//and each cell in that row if(p2Payoffs[f]>p2Payoffs[f+1]){indexP2[p2Counter] = f; p2Counter++;} else if(p2Payoffs[f]==p2Payoffs[f+1]){ indexP2[p2Counter] = f; indexP2[p2Counter+1] = f++; p2Counter = p2Counter+2; } } } //~~~Find Nash Equilibria~~~// int p1Move[p1Counter], p2Move[p1Counter]; int m1Counter=0, m2Counter=0; //If cell indexes match... for(g=0; g<p1Counter; g++){ for(h=0; h<p2Counter; h++){ if(indexP1[g]==indexP2[h]){ //Determine the row in which this occurs for(i=1; i<rows+1; i++){ if(indexP1[g]<(i)*(size/rows){ p1Move[m1Counter] = i-1; m1Counter = m1Counter+1; } } //Determine the column in which this occurs for(j=0; j<cols; j++){ if(indexP1[g]%cols==j){ p2Move[m2Counter] = j; m2Counter = m2Counter+1; } } } } } //~~~Print Normal Form Game~~~// //Print column labels for(k=0; k<cols; k++){ printf(" %d", k); } //Print row labels & payoffs for(m=0; m<rows; m++){ printf("%d ", m); for(n=0; n<m1Counter; n++){ printf("%d,%d ", p1Move[n], p2Move[n]); } } //~~~Print Nash Equilibria~~~// //Finish this after I can read in the file properly }
Errors:
Code:nashEquilibriumFinder.c: In function main: nashEquilibriumFinder.c:26: error: expected ) before string constant nashEquilibriumFinder.c:32: error: expected ) before ; token nashEquilibriumFinder.c:33: error: expected ) before string constant nashEquilibriumFinder.c:76: error: expected ) before { token nashEquilibriumFinder.c:80: error: expected expression before } token



2Likes
LinkBack URL
About LinkBacks


