Skip to content

Instantly share code, notes, and snippets.

@b-adams
Created December 10, 2012 19:39
Show Gist options
  • Save b-adams/4252806 to your computer and use it in GitHub Desktop.
Save b-adams/4252806 to your computer and use it in GitHub Desktop.
L-Force Feedback 121012
int currentPlayer = 1;
char choiceOfPile;
int choiceOfNumber;
int piles ;
int index ;
int players ;
//After user input for piles has been specified
int Pile[piles] ;
printf(" \n\n\n Welcome to Nim \n\n\n");
//getting and storing start values given by the player
piles = numPiles() ;
printf("How many players will be in this game? No more than ten can play.") ;
while(functioningNumber(players) == false)
{
scanf(" %d" , &players) ;
}
for(index = 0 ; index < piles ; index++)
{
int value=0 ;
printf("How many beans are in pile %d to start with? (No more than 10) \n", index+1) ;
switch(index)
{
case 0:
printf("Usually this pile has 3 \n") ;
break;
case 1:
printf("Usually this pile has 4 \n") ;
break;
case 2:
printf("Usually this pile has 5 \n") ;
break;
default:
//*twiddle thumbs*
}
while(functioningNumber(value) == false)
{
scanf(" %d", &value);
}
Pile[index] = value ;
}
//playing game
while(beansRemain(piles, Pile)>0)
{
printf("\n\nPlayer %d's turn\n", currentPlayer);
for(index = 0 ; index < piles ; index++)
{
printf("Pile %d: %d beans\n", index+1, Pile[index]);
}
printf("Which pile do you want to move from?");
scanf(" %c", &choiceOfPile);
printf("How many beans do you want to take?");
scanf("%d", &choiceOfNumber);
Pile[choiceOfPile-1] -= choiceOfNumber;
currentPlayer = currentPlayer+1;
if(currentPlayer>players)
{
currentPlayer=1 ;
}
}

Sorry I am sending so many messages, but I have a piece of code that is annoying me beyond words to describe.

I have been working on making things like the number of players, number of slots, and beans per slot adjustable, then I am going to move on to enforce game rules.

But the code that is getting in my way is the fact that I cannot make the array's values change.

I managed to assign the values in each slot initially, but I can't get them to change when the player chooses to remove beans. I can't figure out why the values are staying the same.

I have this as my code in the trouble area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment