# Thread: keeping track of number of pieces left

1. ## keeping track of number of pieces left

firstly, the program I have to write is Nine Men's Morris or mills, and ancient board game.

at the beginning each player has nine pieces, and one after the other displays them on the board using a row-column coordinates.

My question is: how can I keep track of how many pieces each player has, and how can I make the players alternate?

here is what I have so far, the complete code so it is kind of long.

any help?

thanks,
'
axon

Code:
``` #include <iostream>
#include <cstdlib>
#include <cctype>
using namespace std;

//declaring global variables to hold the positions on the board
char p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12;
char p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24;

//function displaying the board
void displayBoard()
{

cout << "\n\n";
cout << "  1  2  3  4  5  6  7\n\n"
<< "A "<<p1<<"........"<<p2<<"........"<<p3<<" A\n"
<< "  .        .        .\n"
<< "B .  "<<p4<<"....."<<p5<<"....."<<p6<<"  . B\n"
<< "  .  .     .     .  .\n"
<< "C .  .  "<<p7<<".."<<p8<<".."<<p9<<"  .  . C\n"
<< "  .  .  .     .  .  .\n"
<< "D "<<p10<<".."<<p11<<".."<<p12<<"     "<<p13<<".."<<p14<<".."<<p15<<" D\n"
<< "  .  .  .     .  .  .\n"
<< "E .  .  "<<p16<<".."<<p17<<".."<<p18<<"  .  . E\n"
<< "  .  .     .     .  .\n"
<< "F .  "<<p19<<"....."<<p20<<"....."<<p21<<"  . F\n"
<< "  .        .        .\n"
<< "G "<<p22<<"........"<<p23<<"........"<<p24<<" G\n\n"
<< "  1  2  3  4  5  6  7\n"
<< endl;

}

void matchPosition(char row, int column)
{

if(row=='A' && column==1) {p1='x';}
else if(row=='A' && column==4) {p2='x';}
else if(row=='A' && column==7) {p3='x';}
else if(row=='B' && column==2) {p4='x';}
else if(row=='B' && column==4) {p5='x';}
else if(row=='B' && column==6) {p6='x';}
else if(row=='C' && column==3) {p7='x';}
else if(row=='C' && column==4) {p8='x';}
else if(row=='C' && column==5) {p9='x';}
else if(row=='D' && column==1) {p10='x';}
else if(row=='D' && column==2) {p11='x';}
else if(row=='D' && column==3) {p12='x';}
else if(row=='D' && column==5) {p13='x';}
else if(row=='D' && column==6) {p14='x';}
else if(row=='D' && column==7) {p15='x';}
else if(row=='E' && column==3) {p16='x';}
else if(row=='E' && column==4) {p17='x';}
else if(row=='E' && column==5) {p18='x';}
else if(row=='F' && column==2) {p19='x';}
else if(row=='F' && column==4) {p20='x';}
else if(row=='F' && column==6) {p21='x';}
else if(row=='G' && column==1) {p22='x';}
else if(row=='G' && column==4) {p23='x';}
else if(row=='G' && column==7) {p24='x';}

}

//function displaying prompt and storring player's move
void displayPromptAndGetMove()
{

char letter;
int number;

cout << "\nEnter a move position: ";
cin >> letter >> number;

letter = toupper(letter); //converting the letter to upper case

matchPosition(letter, number);

}

void determinePlayerToMove()
{
int playerX = 9;
int playerO = 9;
char playerValue;

if (playerX==9){playerValue = 'X';}
else if (playerX==8 && playerO==9){playerValue = 'O';}

}

int main(){

//setting all the global variables equal a period (.)
p1 = p2 = p3 = p4 = p5 = p6 = p7 = p8 = p9 = p10 = p11 = p12 = '.';
p13 = p14 = p15 = p16 = p17 = p18 = p19 = p20 = p21 = p22 = p23 = p24 = '.';

bool notDone = true;

displayBoard();

while(notDone){

determinePlayerToMove();
displayPromptAndGetMove();
displayBoard();

}
return 0;
}```
PS. so basically I'm trying to figure out function determinePlayerToMove, which when executed will give me either a char playerValue of 'X' or 'O', then playerValue will replace 'x' that is currently in the matchPosition() function

2. Have a counter that counts up the number of moves so far, if the counter is odd, then its player 'X' turn, if even, then its 'O' turn, or vice-versa.

3. i figured something else out, but this might be much easier!

thanks!

axon