# Thread: Winning conditions (Connect 4)

1. ## Winning conditions (Connect 4)

I have a Connect 4 game almost complete.. but i'm having trouble coding the winning conditions. I know I could do it with like 50 if statements but that seems highly unreasonable.

Can any of you experienced coders help me? This is what I have so far; its extremly ugly..

Code:
```	USHORT row = 0;
for (USHORT i = 0; i<4; i++)
{
for (USHORT ii = 1; ii<5; ii++)
{
for (USHORT iii = 2; iii<6; iii++)
{
for (USHORT iiii = 3; iiii<7; iiii++)
{
if ((board[row][i] == board[row][ii]) && (board[row][ii] == board[row][iii]) && (board[row][iii] == board[row][iiii]))
{
if (player == player1)
{
//horizontal win;
return 1;
} else {
//horizontal win;
return 2;
}
}
if (iiii == 6)
{
if (row < 6)
{
row++;
}
i = 0;
ii = i++;
iii = ii++;
iiii = iii++;
}
}
}
}
}```
Does that seem reasonable?

2. since there are a finite amount of winning conditions... [and many of them are very similar...] you can do it with loops... you don't need anything really nested like you have, but you can easily go through all conditions provided you know what they are...

3. I thought we already answered this. There was a great algorithm posted in another connect 4 thread. You may want to check that out.

4. Sorry, I missed that thread.. and im having trouble locating it. Anyone know what its name was?