# Connect four

• 06-08-2002
Tasha2g
Connect four
Im am using a matrix to make a connect four game, when player1 selects a position the value is changed to 1, when player2 selects ithe value becomes 2, Can someone PLEASE tell me how i can test when the player has won the game, either by have four diagonally,vertically, or horizontally.

• 06-10-2002
Uraldor
why dont you think about it yourself. try a few things out and then post again (when you've had a go).

At least try and do it yourself before asking to be spoon fed!

If you have tried it yourself already, show us what you have tried and we'll show you how to fix it!

U.
• 06-10-2002
Hunter2
I made a tic-tac-toe game... the diagonals were sort of manual (if this == 1 && that == 1 && this == 1), but for rows and columns... try for loops :D

(e.g.)
Code:

```for(int x = 0; x < 3; ++x) {     if(positions[x][0] == 1 && positions[x][1] == 1 && (etc.))           playerWins(1); // or something like that }```
I'm too lazy to figure out how to do it for connect 4 by myself, but give that a thought :)
• 06-11-2002
I hope this help, for instance instead of using a matrix use a single dimension array. The spaces needed is constant. For example for tic-tac-toe there is only 9 spaces available so just declare an array of 9 spaces.

1 2 3
---|---|---
4| 5 | 6
----|---|--
7 8 9

the same could work for Connect 4. There are only 42 places that you choose from. an array of of 42 spaces.

1 2 3 4 5 6
7 8 9 10 11 12
13
19
25