Thread: Connect four

  1. #1
    Registered User
    Join Date
    Jun 2002

    Arrow 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.

    Thanks in advance!!

  2. #2
    Registered User
    Join Date
    Dec 2001
    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!

    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    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

    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
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    Registered User cMADsc's Avatar
    Join Date
    Jun 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
    Last edited by cMADsc; 06-11-2002 at 01:31 PM.
    There are those who say they can, and there are those who acutally do. can not learn programming in a class, you have to learn it on your own

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Non-blocking connect()?
    By pobri19 in forum Networking/Device Communication
    Replies: 9
    Last Post: 04-22-2009, 03:40 PM
  2. connect timeout
    By X PaYnE X in forum Networking/Device Communication
    Replies: 8
    Last Post: 05-14-2005, 09:30 PM
  3. Client timed-out once on connect(), can never connect() again
    By registering in forum Networking/Device Communication
    Replies: 6
    Last Post: 10-28-2003, 03:46 PM
  4. MySQL Connect from Outside Computer
    By juschillin in forum Windows Programming
    Replies: 0
    Last Post: 09-27-2002, 08:02 AM
  5. Advanced connect four game
    By Ion Blade in forum C++ Programming
    Replies: 10
    Last Post: 07-28-2002, 07:52 AM