Nutshell, I have an algorithm... I'll post it here..
Actually, I'll just post the code, and let you figure it out
(I'm not really sure what I was thinking anyway)
Code:
int checkWin(char player)
{
store = 0;
for (i = 0; i<4; i++)
{
//cout << "i" << i //Debugging;
if ((board[store][i] == board[store][i+1]) &&
(board[store][i+1] == board[store][i+2]) &&
(board[store][i+2] == board[store][i+3]) &&
(board[store][i+3] != blankchar))
{
return 1;
} else {
if (i == 3) // Is this the last loop through?;
{ // if not, i is never reset, the loop ends, and 0 returns;
if (store != 5) //Is this the last column?;
{
store++;
i = -1; //-1 instead of 0 because it's incremented at the end of the loop;
}
}
}
}
store = 0;
for (i = 0; i<3; i++)
{
//cout << "i" << i; //Debugging;
if ((board[i][store] == board[i+1][store]) &&
(board[i+1][store] == board[i+2][store]) &&
(board[i+2][store] == board[i+3][store]) &&
(board[i+3][store] != blankchar))
{
return 1;
} else {
if (i == 2) // Is this the last loop through?;
{ // if not, i is never reset, the loop ends, and 0 returns;
if (store != 6) //Is this the last column?;
{
store++;
i = -1; //-1 instead of 0 because it's incremented at the end of the loop;
}
}
}
}
for (i=0; i<5; i++)
{
for (ii=0; ii<4; ii++)
{
if ((board[i][ii] == board[i+1][ii+1])
&& (board[i][ii] == board[i+2][ii+2])
&& (board[i][ii] == board[i+3][ii+3])
&& (board[i+3][ii+3] != blankchar))
{
return 1;
}
}
}
for (i=6; i>3; i--)
{
for (ii=0; ii<4; ii++)
{
if ((board[i][ii] == board[i-1][ii+1])
&& (board[i][ii] == board[i-2][ii+2])
&& (board[i][ii] == board[i-3][ii+3])
&& (board[i-3][ii+3] != blankchar))
{
return 1;
}
}
}
return 0;
}