Mancala C++ Project (Part 2) *ALL HELP NEEDED*

***** MY QUESTION(S): So I'm at brink of finishing my project and I'm stuck and have a few issues. Firstly, I mention under rules for play mancala in TRICKS
"IF, when dropping stones into holes, you drop a stone into a hole that was
* previously empty, AND the hole is on your side, AND that was the last stone
* in your hand, you take all of the stones in the hole directly above,
* and place them into your mancala.". I can't seem to figure out HOW I can implement this? I want to put it under void makemove and I was thinking of using pass by reference/pointers ? also the score isn't displaying the score correctly it remains at p1: 0 & p2:0 despite the player's mancala's having the stones?



#include <iostream>
#include <string>


using namespace std;


/*
RULES FOR PLAYING 'MANCALA'

* The point of the game is get as much stones in your mancala(or store).
* Player 1's Mancala is on the left and player 2's Mancala is on the right
* Both players have 4 pits, and one Mancala.Each pit has 4 stones which amounts
* to 16 stones for each player,


* During a turn, a player grabs all of the stones in a pit on their side and
* drops them, one by one on each pit in a counter-clockwise direction.
* Players MAY place stones in their OWN mancala(it too counts as a pit), but
* They MUST skip over their opponent's mancala. Players MAY place stones in
* pits on their opponent's side. This continues until the player has no more
* stones in his hand. It is then their opponents turn.

* TRICKS: IF, when dropping stones into the pits, & drop a stone into your own
* mancala, & that is the LAST stone in your hand, then you get to go again.
* IF, when dropping stones into holes, you drop a stone into a hole that was
* previously empty, AND the hole is on your side, AND that was the last stone
* in your hand, you take all of the stones in the hole directly above,
* and place them into your mancala.

* STRATEGIES: On your first turn (and if you're going first), play the
* hole that is five holes away from your mancala. That way, the last stone you
* place will land in your mancala, and you get a free turn. After using your
* second turn, if your opponent plays a hole that is two or one hole(s) away
* from their mancala, play the hole that is six holes away from your mancala.
* You get another free turn!
*/

//Array to hold vales in pits, and score
void displayboard(int boardvalue[14], int score[2]);
void makemove(int boardvalue[14],int &player, int score[2]);
void winner(int score[2]);


int main()
{ //Arrays to hold values for pits, and overall board value
int finished[2] = {4,4};
int score[2] = {0};
int boardvalue[14];
int player = 0;
for (int i = 0; i < 14; i ++)
{
boardvalue[i] = 4;
}
boardvalue[0] = 0;
boardvalue[7] = 0;


while (finished[0] > 0 && finished[1] > 0)
{
displayboard(boardvalue, score);
finished[0] = 0;
finished[1] = 0;
//For loop to make a move
for (int i = 1; i < 14; i ++)
{
if((i >0 && i <7) && boardvalue[i] > 0 )
finished[0]++;
if((i >7 && i <13) && boardvalue[i] > 0 )
finished[1]++;
}
makemove(boardvalue, player, score);
player = !player;
}
}

void displayboard(int boardvalue[14], int score[2])
{
cout << "Player 1 : " << score[0] << " " << "Player 2 : "
<< score[1] << endl;
cout << endl << "\tA\tB\tC\tD\tE\tF\n\t";
for (int i = 1; i < 7; i ++)
cout << boardvalue[i] << "\t";
cout << endl << " " << boardvalue[0] << "\t\t\t\t\t\t "
<< boardvalue[7] << endl << "\t";
for (int i = 8; i < 14; i ++)
cout << boardvalue[i] << "\t";
cout << endl << "\tG\tH\tI\tJ\tK\tL";

cout << endl << endl << endl;
}

void makemove(int boardvalue[14],int &player, int score[2])
{
string Players[2] = {"Player 1","Player 2"};
bool ok;
char col;
int stones, x, pit, start_pit;
cout << Players[player] << "'s turn!" << endl;


do
{
ok = false;
cout << endl << "Which column do you want to pick from ? (";
cout<<(player==0 ? " A to F " : " G to L ");
cout << ") _\b";
cin >> col;
col = toupper(col);
if(((col >= 'A' && col <= 'F') && player == 0) &&
boardvalue[col-64] > 0 || ((col >= 'G' && col <= 'L')
&& player == 1) && boardvalue[col-63] > 0)
ok = true;
else
cout << endl << "There are NO stones in that pit."<<endl;

if(((col>='A'&&col<='F')&&player == 1) || ((col >= 'G' && col <= 'L')
&& player == 0))
cout << "Those stones don't belong to you. Try again.." << endl;
if(col > 'L')
cout << "ERROR: Location does not exist" << endl;
}while (!ok);
//while (((col <'A' || col > 'F') && player == 0) &&
//boardvalue[col-64] == 0 || ((col <'G' || col > 'L') &&
//player == 1) && boardvalue[col-63] == 0)
if(col-64 < 7)
{
stones = boardvalue[col-64];
boardvalue[col-64] = 0;
pit = (col-64)-1;
start_pit = (col-64);
if(pit<0)
pit = 8;
}
else
{
stones = boardvalue[col-63];
boardvalue[col-63] = 0;
pit = (col-63)+1;
start_pit = (col-63);
if(pit>13)
pit = 7;
}
cout << "Stones = " << stones << endl;

for(x = 0; x < stones; x++)
{
if(pit >= 0 && pit < 8 )
{
if(x < stones)
{

if(player == 1)
{
if(pit == 0)
{
pit = 8;
//boardvalue[pit]++;
//continue;

}
}
if(pit >= 0 && pit < 8 )
{
boardvalue[pit]++;
if(x+1 < stones)
{
pit--;
if (pit < 0)
pit = 8;
}
}
}
}

if(pit > 7 && pit < 14 )
{

if(x < stones)
{
if(player == 0)
{
if(pit+1 == 1)
{
pit = 6;
//boardvalue[pit]++;
//continue;
}
}
boardvalue[pit]++;
if(x+1 < stones)
{
pit++;
if(pit > 13)
pit = 7;
}
}
}
}

if(abs(pit-7 == start_pit) && boardvalue[start_pit] == 0 )
{
if(player == 0)
{
score[0]+= boardvalue[pit];
boardvalue[0]+= boardvalue[pit];
boardvalue[pit] = 0;
}
if(player == 1)
{
score[1]+= boardvalue[pit];
boardvalue[7]+= boardvalue[pit];
boardvalue[pit] = 0;
}
}
if(player == 1)
{
if(pit == 7 && x == stones)
{
cout << Players[player] << " has another turn!"<<endl;
player = !player;
}
}
if(player == 0)
{
if(pit == 0 && x == stones)
{
cout << Players[player] << " has another turn!"<<endl;
player = !player;
}
}

}
HERE IS AN UNFINISHED SAMPLE OF THE GAME: (**When you run the program the 0's[the mancala,or store] are on the outside and placed correctly it isn't display well here on the forum for some reason.**)

Player 1 : 0 Player 2 : 0

A B C D E F
4 4 4 4 4 4
0 0
4 4 4 4 4 4
G H I J K L


Player 1's turn!

Which column do you want to pick from ? ( A to F ) D
Stones = 4
Player 1 has another turn!
Player 1 : 0 Player 2 : 0

A B C D E F
5 5 5 0 4 4
1 0
4 4 4 4 4 4
G H I J K L


Player 1's turn!

Which column do you want to pick from ? ( A to F ) A
Stones = 5
Player 1 : 0 Player 2 : 0

A B C D E F
0 5 5 0 4 4
2 0
5 5 5 5 5 4
G H I J K L


Player 2's turn!

Which column do you want to pick from ? ( G to L ) H
Stones = 5
Player 2 has another turn!
Player 1 : 0 Player 2 : 0

A B C D E F
0 5 5 0 4 4
2 1
5 0 6 6 6 5
G H I J K L


Player 2's turn!

Which column do you want to pick from ? ( G to L ) J
Stones = 6
Player 1 : 0 Player 2 : 0

A B C D E F
0 5 5 1 5 5
2 2
5 0 6 0 7 6
G H I J K L


Player 1's turn!

Which column do you want to pick from ? ( A to F ) D
Stones = 1
Player 1 : 0 Player 2 : 0

A B C D E F
0 5 6 0 5 5
2 2
5 0 6 0 7 6
G H I J K L


Player 2's turn!

Which column do you want to pick from ? ( G to L ) G
Stones = 5
Player 1 : 0 Player 2 : 0

A B C D E F
0 5 6 0 5 5
2 2
0 1 7 1 8 7
G H I J K L


Player 1's turn!

Which column do you want to pick from ? ( A to F ) F
Stones = 5
Player 1 : 0 Player 2 : 0

A B C D E F
1 6 7 1 6 0
2 2
0 1 7 1 8 7
G H I J K L


Player 2's turn!

Which column do you want to pick from ? ( G to L ) K
Stones = 8
Player 1 : 0 Player 2 : 0

A B C D E F
2 7 8 2 7 1
2 3
0 1 7 1 0 8
G H I J K L


Player 1's turn!

Which column do you want to pick from ? ( A to F ) E
Stones = 7
Player 1 : 0 Player 2 : 0

A B C D E F
3 8 9 3 0 1
3 3
1 2 8 1 0 8
G H I J K L


Player 2's turn!

Which column do you want to pick from ? ( G to L ) I
Stones = 8
Player 1 : 0 Player 2 : 0

A B C D E F
3 8 10 4 1 2
3 4
1 2 0 2 1 9
G H I J K L


Player 1's turn!

Which column do you want to pick from ? ( A to F ) C
Stones = 10
Player 1 : 0 Player 2 : 0

A B C D E F
4 9 0 4 1 3
4 5
2 3 1 3 2 10
G H I J K L
This abs(pit-7 == start_pit) is probably not what you want.

You can simplify your code if you make calculations like col-64 only once.

Another calculation would be col - 'A'. This would return the 0 based index directly.

Consider to use code tags: [code]Your code[/code]
Read this: http://www.cplusplus.com/articles/z13hAqkS/
Topic archived. No new replies allowed.