#include <iostream>
#include <vector.h>
bool finished(vector <int> displayboard);
void displayboard(vector <int> boardvalue);
void makemove(vector <int> &boardvalue, int player);
usingnamespace std;
void makemove(vector <int> &boardvalue, int player)
{
char position; int numposition;
cout << "\nWhich column do you want to pick from? ";
cin >> position;
if (player == 1)
{
switch(position)
{
case'A':
numposition=1;
break;
case'B':
numposition=2;
break;
case'C':
numposition=3;
break;
case'D':
numposition=4;
break;
case'E':
numposition=5;
break;
case'F':
numposition= 6;
break;
default:
cout << "Enter the letter of one of the pits";
break;
}
}
if (player == 2)
{
switch(position)
{
case'A':
numposition=13;
break;
case'B':
numposition=12;
break;
case'C':
numposition=11;
break;
case'D':
numposition=10;
break;
case'E':
numposition=9;
break;
case'F':
numposition=8;
break;
default:
cout << "Enter the letter of one of the pits";
break;
}
}
int numstones = boardvalue[numposition];
boardvalue[numposition]=0;
for (int i = 1; i < numstones; i++)
{
boardvalue[(numposition + i)] += 1;
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bool finished(vector <int> displayboard)
{
if (displayboard[1] ==0 && displayboard[2] ==0 && displayboard[3] ==0 && displayboard[4] ==0 && displayboard[5] ==0 && displayboard[6] ==0 ||displayboard[13] ==0 && displayboard[8] ==0 && displayboard[9] ==0 && displayboard[10] ==0 && displayboard[11] ==0 && displayboard[12] ==0)
returntrue;
elsereturnfalse;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void displayboard(vector <int> boardvalue)
{
cout << " " << boardvalue[13] << " " << boardvalue[12] << " " << boardvalue[11] << " " << boardvalue[10] << " " << boardvalue[9] << " " << boardvalue[8];
cout << endl << boardvalue[0] << " " << boardvalue [7] << endl;
cout << " " << boardvalue[1] << " " << boardvalue[2] << " " << boardvalue[3] << " " << boardvalue[4] << " " << boardvalue[5] << " " << boardvalue[6];
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 << " A B C D E F\n";
}
displayboard(boardvalue);
if (player == 2)
{
cout << "\n A B C D E F\n";
}
if (player == 1)
{
player = 2;
}
else
player = 1;
}
return(0);
}
Specifically in makemove towards the end at
1 2 3 4 5 6
int numstones = boardvalue[numposition];
boardvalue[numposition]=0;
for (int i = 1; i < numstones; i++)
{
boardvalue[(numposition + i)] += 1;
}
It ends when the vector gets to 13, though it should keep looping until it runs out of stones.
I know there's a simple solution to the problem, and I feel really dumb because it is escaping my grasp right now.
Any other advice would be appreciated as well.