I am working on a board game, which has a game piece counter. However, I cannot figure out how can I make one with for loop, decrementing every time a piece will be eaten by another piece(character). Initially red pieces and blue pieces are 12 and as the game progresses, they will be eaten and so the game piece should be updated. I am also not recommended to use global variables unless user-defined function. What can I do?
#include<stdio.h>
char board[8][8] = {
{'-', 'B', '-', 'B', '-', 'B', '-', 'B'},
{'B', '-', 'B', '-', 'B', '-', 'B', '-'},
{'-', 'B', '-', 'B', '-', 'B', '-', 'B'},
{' ', '-', ' ', '-', ' ', '-', ' ', '-'},
{'-', ' ', '-', ' ', '-', ' ', '-', ' '},
{'R', '-', 'R', '-', 'R', '-', 'R', '-'},
{'-', 'R', '-', 'R', '-', 'R', '-', 'R'},
{'R', '-', 'R', '-', 'R', '-', 'R', '-'}};
void
printBoard()
{
int i , j , k ;
printf("\n ");
for(i=0;i<8;i++)
printf(" %d", i);
printf(" \n");
for(k=0;k<8;k++)
{
printf(" ");
for(i=0;i<42;i++)
{
printf("-");
}
printf(" \n");
printf(" %d ", k);
for(j=0;j<8;j++)
{
printf("|| %c ", board[k][j]);
}
printf("|| \n");
}
printf(" ");
for(i=0;i<42;i++)
{
printf("-");
}
printf(" \n");
}
int gamePiece(int Player1, int BluePiece, int Player2, int RedPiece)
{
int i, j;
printf("\n\Game piece counter:");
//for loop
printf("\nPlayer %d = %d",Player1,BluePiece);
printf("\nPlayer %d = %d",Player2,RedPiece);
return 0;
}
int main(){
int Player1, BluePiece=12, Player2, RedPiece=12;
gamePiece(Player1, BluePiece, Player2, RedPiece);
return 0;
}
`