Need help understanding what I am doing wrong. This is part of an assignment that I am doing through distance learning. Thanks.
I am passing a pointer and an array of players (2 players). Where players are a struct:
struct player
{
char name[NAMELEN + 1];
int score; /* count of number of pieces on the board */
colour token_colour;
};
struct player * play_game(struct player players[])
{
gameboard board;
struct player * current, *other;
gameboard_init(board);
player_init(&players[0],1);
player_init(&players[1],2);
**randomize_game(players,current);**
/* replace this NULL return value with the appropriate return value */
return NULL;
}
I then attempt to set the pointer(curplayer) to the player that won the randomize roll to go first. I am stepping through using GDB and can confirm that the value is the same before as it is after the command. Please help! with explanations of what im doing wrong:
curplayer= &players[0];
void randomize_game(struct player players[],struct player* curplayer)
{
int p;
time_t t;
srand((unsigned) time(&t));
p = rand() % 2;
if(p==0){
**curplayer= &players[0];**
players[0].token_colour = CC_WHITE;
players[1].token_colour = CC_RED;
}else{
**curplayer= &players[1];**
players[0].token_colour = CC_RED;
players[1].token_colour = CC_WHITE;
}
}
Thanks