Like Tree1Likes
  • 1 Post By quzah

trouble with the tic tac toe grid

This is a discussion on trouble with the tic tac toe grid within the C Programming forums, part of the General Programming Boards category; Hi everyone! I trying to write a code for tic tac toe game,trying to form the grid and place the ...

  1. #1
    Registered User shruthi's Avatar
    Join Date
    Jan 2012
    Posts
    59

    trouble with the tic tac toe grid

    Hi everyone!
    I trying to write a code for tic tac toe game,trying to form the grid and place the character in the specified location.The problem is that,for example when I try to place the character in 2nd row,2nd col and if 2nd row and 3rd col already has a char,it get shifted out of the grid.Could you please help me understand this better,I am trying to change spaces but it's not helping.
    Code:
    #include<stdio.h>
    int grid[3][3];
    void block()
    {
        int row,col;
        printf("\t\ttic tac toe\n");
        for(row=1;row<=3;row++)
        {
            printf("\t\t___________________\n");
            printf("\t\t|     |     |     |\n");
            for(col=1;col<=3;col++)
            {
                if(grid[row][col]==1)
                {
                    if(col==1)
                    printf("\t\t   1");
    
    
    
    
                    else if(col==2)
                    printf("\t\t         2");
    
    
                    else
                    printf("\t\t               3");
    
    
                }
    
    
            }
    
    
    
    
        printf("\n");
        printf("\t\t|     |     |     |\n");
        }
        printf("\t\t___________________\n");
    
    
    }
    int main()
    {
        int i,row,col;
        block();
        for(row=1;row<=3;row++)
        {
            for(col=1;col<=3;col++)
            grid[row][col]=0;
        }
        for(i=0;i<9;i++)
        {
            printf("enter the row no.\n");
            scanf("%d",&row);
            printf("enter the col no\n");
            scanf("%d",&col);
            grid[row][col]=1;
            block();
        }
        return 0;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What is a tic tac toe board? It's:

    a character a bar a character a bar a character
    a row of bars
    a character a bar a character a bar a character
    a row of bars
    a character a bar a character a bar a character

    So you just need to draw exactly that, every time you need to redraw the board. The character you draw depends if it's empty (a space), if it's an X (put an x) or an O (put an o).


    Quzah.
    iMalc likes this.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User shruthi's Avatar
    Join Date
    Jan 2012
    Posts
    59
    Quote Originally Posted by quzah View Post
    What is a tic tac toe board? It's:

    a character a bar a character a bar a character
    a row of bars
    a character a bar a character a bar a character
    a row of bars
    a character a bar a character a bar a character

    So you just need to draw exactly that, every time you need to redraw the board. The character you draw depends if it's empty (a space), if it's an X (put an x) or an O (put an o).


    Quzah.
    Thank you,got it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Grid
    By mortalc in forum C Programming
    Replies: 7
    Last Post: 03-12-2011, 05:23 AM
  2. help with the grid
    By wannabec++ in forum C++ Programming
    Replies: 2
    Last Post: 12-05-2010, 01:43 PM
  3. 4x4 grid in C
    By amorvisa in forum C Programming
    Replies: 7
    Last Post: 10-17-2007, 11:13 PM
  4. grid
    By xlnk in forum Windows Programming
    Replies: 3
    Last Post: 12-14-2002, 07:40 PM
  5. hex grid
    By waterst in forum C Programming
    Replies: 2
    Last Post: 10-30-2002, 02:36 PM

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