help with connect 4

This is a discussion on help with connect 4 within the C Programming forums, part of the General Programming Boards category; hey guys, its me again. well this is my whole program so far. i have been trying to figure out ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    6

    help with connect 4

    hey guys, its me again. well this is my whole program so far. i have been trying to figure out what is the problem and why isnt it compiling and just overall, trying to make it work. hope you guys can assist me again. thanks.
    code:
    -----------------------------------------------------------------------------------
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #define N 9
    #define F 4

    void print_board ( char board[N][N] ) {
    int r, c;
    for ( r = 0 ; r < N ; r++ ) {
    for ( c = 0 ; c < N ; c++ ) {
    printf( "( %c )", board[r][c] );
    }
    printf( "\n" );
    }
    }

    int check_for_line ( char board[N][N], int start_r, int start_c )
    {
    int r1, c1;

    for ( r1 = -1 ; r1 <= 1 ; r1++ )
    {
    for ( c1 = -1 ; c1 <= 1 ; c1++ )
    {
    int i, r, c;

    if ( r1 == 0 && c1 == 0 ) continue;

    for ( i = 1 ; i < F ; i++ )
    {
    r = start_r + r1 * i;
    c = start_c + c1 * i;

    if ( r < 0 || r >= N ) break;
    if ( c < 0 || c >= N ) break;

    if ( board[r][c] != 'X' || board[r][c] != 'O') break;
    }

    if ( i == F )
    return 1;
    else return 0;
    }
    }
    }

    void check ( char board[N][N] )
    {
    int r, c;
    for ( r = 0 ; r < N ; r++ )
    {
    for ( c = 0 ; c < N ; c++ )
    {
    if ( board[r][c] == 'X' || board[r][c] == 'O' )
    {
    check_for_line( board, r, c );
    }
    }
    }
    }

    int player(char board[N][N])
    {
    int sel,i;

    print_board( board );

    printf("Type a number between 1 and %d to make a move: ",N);scanf("%d",&sel);
    for ( i = N-1 ; i >= 0 ; i-- )
    {
    if (board[i][sel-1] == ' ')
    {
    board[i][sel-1] = 'X';break;
    }
    }
    if(check( board )==1)
    {
    printf("You Win!\n");
    printf("The Final Board: \n");
    print_board( board );
    return 1;
    }
    else
    return 0;
    }

    int computer(char board[N][N])
    {
    int sel1,i;

    srand(time(NULL));
    sel1=rand()%N+1;

    printf("Computer selects column number %d\n",sel1);

    for ( i = N-1 ; i >= 0 ; i-- )
    {
    if (board[i][sel1-1] == ' ')
    {
    board[i][sel1-1] = 'O';break;
    }
    }
    if( check( board )==1 )
    {
    printf("Computer wins!\n");
    printf("The Final Board: \n");
    print_board( board );
    return 1;
    }
    else
    return 0;
    }
    int main (void)
    {
    char board[N][N];
    int i,j;

    printf("Welcome to Connect %d\n",F);


    for(i=0;i<N;i++)
    for(j=0;j<N;j++)
    board[i][j]=' ';

    do(

    player(board);
    computer(board);

    )while(player(board)!=1 || computer(board)!=1);

    return 0;
    }

  2. #2
    Unregistered
    Guest
    For one thing, your "do" loop in main needs {} not ()...

    Also, your check function you declared as void (not returning a value) and then you try to compare it to 1... you need to declare it as an "int" and then add a return statement to it that will send back a return value.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    6
    ok thanx. i changed the DO brakets but it still dont work. thanx anywayz. can anybody else assist me. thank you

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, 04:40 PM
  2. connect timeout
    By X PaYnE X in forum Networking/Device Communication
    Replies: 8
    Last Post: 05-14-2005, 10: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, 09:02 AM
  5. Advanced connect four game
    By Ion Blade in forum C++ Programming
    Replies: 10
    Last Post: 07-28-2002, 08:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21