Thread: TIC-TAC-Toe Question

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    1

    TIC-TAC-Toe Question

    can some tell me how to make tic tac toe program WITHOUT using array..?? and its in C.. i'm not asking for someone todo my work..just a wanted alittle help..

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Using a single 32bit integer and bit masking, you can easily* pull this off.
    Code:
    #define X0 (1<< 0)
    #define O0 (1<<10)
    ...
    #define X8 (1<< 8)
    #define O8 (1<<18)
    
    long board = 0;
    
    if( board & X0 || board & O0 )
        printf("The first spot on the board is filled by %c", board & X0 ? 'X' : 'O' );
    That should get you started.

    [edit] Curses! Foiled again! [/edit]

    Quzah.
    *Your mileage may vary.
    Hope is the first step on the road to disappointment.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Here's another amusing idea:
    Code:
    struct {
        char _0;
        char _1;
        char _2;
        char _3;
        char _4;
        char _5;
        char _6;
        char _7;
        char _8;
    } board;
    
    board._0 = 'X'
    See, no array! You could even have fun with some pointers and use it as an array if you're so inclined. If you're really bored, use the 'offsetof' macro for added fun.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    You could also do it using nine int variables and a lot of if statements...yucky. Why don't you want to use an array?
    Away.

  5. #5
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by Salem
    > Why don't you want to use an array?
    Because its a homework exercise I guess
    Even when I was learing, instructors made no sense. I was supposed to do a CHI Square program in assembler (shudder)
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tic Tac Toe Neural Network
    By glo in forum General AI Programming
    Replies: 4
    Last Post: 06-15-2008, 03:39 PM
  2. Making Tic Tac Toe Smarter
    By abh!shek in forum C Programming
    Replies: 15
    Last Post: 06-05-2008, 10:43 AM
  3. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 06:25 PM
  4. tic tac toe question (logic question)
    By revelation437 in forum C++ Programming
    Replies: 3
    Last Post: 06-09-2003, 03:11 PM
  5. Help with Tic Tac Toe game
    By snef73 in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2003, 08:33 AM