Mancala C++ Project

Having trouble with this for loop that places the number of "stones" for player one counterclockwise but for some reason it isnt allow the 2nd player to do the same it only allows the pebbles to stay on there row. here is an example of how the program runs:

4 4 4 4 4 4
0 0
4 4 4 4 4 4
A B C D E F

Player 1's turn!
Which column do you want to pick from? E
G H I J K L
4 4 4 4 4 5
0 1
4 4 4 4 0 5
Player 2's turn!
Which column do you want to pick from? H
5 0 4 4 4 5
0 1
4 4 4 4 0 5
A B C D E F

Player 1's turn!
Which column do you want to pick from? F
G H I J K L
5 0 4 5 5 6
0 2
4 4 4 4 0 0
Player 2's turn!
Which column do you want to pick from? I
6 1 0 5 5 6
0 2
4 4 4 4 0 0
A B C D E F

// HERE IS THE CODE I IMPLEMENTED SPECIFICALLY TO ADD THE STONES AND WHAT NOT Also it is only placing them in 3 places instead of 4?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
:


int main()
{
        vector <int> boardvalue(14);
	int player = 1;
	for (int i = 0;  i <= boardvalue.size(); i ++)
	{
		 boardvalue[i] = 4;
	}
	boardvalue[0] = 0; boardvalue[7] = 0;
	displayboard(boardvalue);
	cout << "\n	A	B	C	D	E	F\n";
	while (!finished(boardvalue))
	{
		if (player == 1)
			{
			cout <<  "\nPlayer 1's turn!";
			}
		else
			{
			cout << "\nPlayer 2's turn!";
			}
		makemove(boardvalue, player);
		if (player == 1)
		{
		cout << "	G	H	I	J	K	L\n";
		}
		displayboard(boardvalue);	
		if (player == 2)
		{
		cout << "\n	A	B	C	D	E	F\n";
		}
		if (player == 1)
			{
			player = 2;
			} 
		else
			player = 1;
        }        
	


  Put the code you need help with here.
You haven't given a sensible amount of code. Nobody can test this, and you are missing the rather crucial routine makemove().

No idea whether it has anything to do with your problem, but you will exceed array bounds when you have <= boardvalue.size() on line 8 (the last element is boardvalue.size()-1), so either code this or change <= to <.

Since there are several versions of the game Mancala you will have to state the rules that you are playing to. Your board display also does not make clear the position (and hence array index) of the two Mancala pots. You can use output tags if you want to align displays of output properly.
Last edited on
My fading memory had me moving Mancala stones clockwise, but that is immaterial for this question.

Even Player 1 is incorrect. If you pick up 4 stones from "E", you should place 1 in F, the pot, L and K. K did not get an extra stone. So, in addition to echoing @lastchance's comments that your code snippet is woefully insufficient, I add that your starting assumption that player 1 plays correctly is false.

Also, comments in the code indicating which boardValue array elements line up with which slots on the board will help us understand how you are trying to model the game.
@doug4

OP wrote..
// HERE IS THE CODE I IMPLEMENTED SPECIFICALLY TO ADD THE STONES AND WHAT NOT Also it is only placing them in 3 places instead of 4?


The OP did say that there is an error in the coding, as only 3 stones are being played and not the 4 as it should.
Last edited on
@doug4

OP wrote..
// HERE IS THE CODE I IMPLEMENTED SPECIFICALLY TO ADD THE STONES AND WHAT NOT Also it is only placing them in 3 places instead of 4?


The OP did say that there is an error in the coding, as only 3 stones are being played and not the 4 as it should.


@OP,

I'm sorry. I read right over that statement. I guess I had nothing to add.
Registered users can post here. Sign in or register to post.