Thread: Boolean, what does it return?

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    16

    Arrow Boolean, what does it return?

    I've just started my C++ class and I'm starting my first program: TicTacToe. My professor posted some hint code to help us out, and one thing he used was a function bool validmove(). I'm trying to write out the function, but I'm not sure what bool does.
    Does bool return only TRUE and FALSE? Any help would be appreciated, thanks.

  2. #2
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    Yes thats correct, bool returns true or false

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    One small point that may cause a problem....may not....

    C++ defines the type "bool" which can be "true" or "false"

    Windows defines the type "BOOL" which can be "TRUE" or "FALSE"

    Looking at a little dissasembly;

    BOOL B;

    bool b;

    B = TRUE; //mov dword ptr [ebp-4],1

    b = true; //mov byte ptr [ebp-8],1
    Notice that the c++ version is addressed as a BYTE (8bit) in memory, but the Windows version is addressed as a DWORD (32bit)........

    They both do the same thing thing......but mixing them can lead to problems...so if your code uses bool, use true & false as opposed to TRUE & FALSE

  4. #4
    Registered User
    Join Date
    Aug 2002
    Posts
    16
    Ok, thanks for the confirmation on bool.

    Another thing, I comliled some code that I wrote, and I get an error message saying: "subscript requires array or pointer type."

    What does this mean?

  5. #5
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    Post code please.

  6. #6
    Registered User
    Join Date
    Aug 2002
    Posts
    16
    Oh sorry, I didn't realize I left it out.

    This is the function that has the problems:

    TicTacToe::Status TicTacToe::gamestatus(void)
    {
    int a, c, r;

    // check for a win on diagonals
    if (board[0] != ' ' && board[0] == board[4] && board[0] == board[8])
    return WIN;
    else if (board[2] != ' ' && board[2] == board[4] && board[2] == board[6])
    return WIN;

    // Check for a win across top row
    if(board[0] != ' ' && board[0] == board[1] && board[0] == board[2])
    return WIN;
    //Check for a win across middle row
    if(board[3] != ' ' && board[3] == board[4] && board[3] == board[5])
    return WIN;
    //Check for a win across bottom row
    if(board[6] != ' ' && board[6] == board[7] && board[6] == board[7])
    return WIN;
    //Check for a win down left column
    if(board[0] != ' ' && board[0] == board[3] && board[0] == board[6])
    return WIN;
    //Check for a win down middle column
    if(board[1] != ' ' && board[1] == board[4] && board[1] == board[7])
    return WIN;
    //Check for a win down right column
    if(board[2] != ' ' && board[2] == board[5] && board[2] == board[8])
    return WIN;

    //Check for game completion
    for(c=0; c<9; ++c)
    if (board[r] == ' ')
    return CONTINUE; // Game is not finished

    return DRAW; // Nothing matches, game is a draw.
    }

  7. #7
    Unregistered
    Guest
    Next time you post code use code tags please.

    I´m not sure you can do like this, I assume that theese functions
    do the same thing, use one function only. Also should it return a datatype which is the same as WIN, CONTINUE and DRAW
    Code:
    TicTacToe::Status TicTacToe::gamestatus(void)
    Code:
    int a,c,r;
    You should always assign a value to a varible before you use it. Varible a is unneccesary and r contain garbage-value which mean that you don´t compare the array correctly.

    Code:
    for(c=0; c<9; ++c)
    if (board[r] == ' ')
    return CONTINUE; // Game is not finished
    Should be if (board[i] == ´´)

    Make also sure that the function returns the right datatype.

    Hope that helps!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  2. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  3. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM
  4. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM