keeping track of number of pieces left

This is a discussion on keeping track of number of pieces left within the C++ Programming forums, part of the General Programming Boards category; firstly, the program I have to write is Nine Men's Morris or mills, and ancient board game. at the beginning ...

  1. #1
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572

    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. #2
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    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. #3
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    i figured something else out, but this might be much easier!

    thanks!

    axon

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. Odd 3D Invis Objects?
    By Zeusbwr in forum Game Programming
    Replies: 4
    Last Post: 12-07-2004, 06:01 PM
  3. Keeping track of values without an array
    By m712 in forum C++ Programming
    Replies: 5
    Last Post: 11-07-2002, 09:49 AM
  4. Please help me
    By teedee46 in forum C++ Programming
    Replies: 9
    Last Post: 05-06-2002, 11:28 PM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21