Thread: Connect 4 in c

  1. #1
    Registered User
    Join Date
    Nov 2016
    Posts
    5

    Connect 4 in c

    Hey im trying to do a connect 4 game in c with multiD arrays
    insert
    Code:
    void drawboard(int board[6][7])
    {
    int i;
    int j;
    printf(" 1 2 3 4 5 6 7 \n");
    for(i = 5; i >= 0; i = (i - 1))
    {
    for(j = 0; j < 7; j = (j + 1))
    {
    printf(" | ");
    if(board[i][j] == 1)
    {
    printf("X");
    }
    else if(board[i][j] == 2)
    {
    printf("");
    }
    else if(board[i][j] == 3)
    {
    printf("4");
    }
    else if(board[i][j] == 0);
    {
    printf(" ");
    }
    }
    printf(" | \n");
    }
    printf(" ------------------------ \n");
    }]


    All I really have is this function for drawing the board our teacher provided. Im just trying to find a place to start. Does anyone have advice on how I can fill the board
    I want to be able to ask in a loop
    printf("What column to place O");
    "place that O in a column that will keep track of what has been put there"
    and so on until I can check for wins

  2. #2
    Registered User
    Join Date
    Aug 2013
    Posts
    40
    I'm not a pro but I just did this for university a few weeks ago. What you want to do is to break it down into separate tasks and write a shot function for each one. Then you call just call them all in order in the main body of code in a loop like this;

    input form player one
    check input
    place move in the array
    check to see if someone wins
    check to see if draw
    input form player two
    check input
    place move in the array
    check to see if someone wins
    check to see if draw

    it can then just go round and round until someone wins or there is a draw.
    You might want to do a few things to setup before this main loop like initializing the board array with black spaces.

  3. #3
    Registered User
    Join Date
    Nov 2016
    Posts
    5
    Gotcha! thanks man

  4. #4
    Registered User
    Join Date
    Nov 2016
    Posts
    5
    Actually not to harp you for answers but do you have an idea on how your checkwin function worked or the psuedocode for something like that if im doing multid arrays

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. connect four in C
    By kiwi101 in forum Game Programming
    Replies: 1
    Last Post: 05-04-2012, 11:35 PM
  2. connect to tpm
    By zahra34 in forum Windows Programming
    Replies: 5
    Last Post: 10-18-2009, 06:46 AM
  3. USB Connect
    By CorX in forum Networking/Device Communication
    Replies: 3
    Last Post: 05-12-2009, 09:50 AM
  4. 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
  5. Connect four
    By Tasha2g in forum Windows Programming
    Replies: 3
    Last Post: 06-11-2002, 01:18 PM

Tags for this Thread