Help in finding the error

I am making a tic tac toe game in the console.
You can see my code here:
http://pastebin.com/z8tYxipN

The code is not yet completed, so many functions are not being used!

But now to the problem:
As you can see in the void Peg_t::UserMove() function, I am making the program check if the specified move is on a blank position or not.

Now when I run the program this is what happens:

        1 2 3
      1  | |
        -|-|-
      2  | |
        -|-|-
      3  | |
Please enter the position of the Place you want to move:  11
        1 2 3
      1  | |
        -|-|-
      2  | |
        -|-|-
      3  | |
You made an illegal move! Turn Skipped
--------------------------------------------------------------------------------

This happens for all the nine moves, on all the turns. Any help??
Do some debugging. What is the value of board[0] when it is decided that it's an illegal move?
If I am using the debugger to check the value of board [0] at that moment, it is: 0x013cc150 ""
It seems to be a memory location to me.
You might find it easier to debug by outputting the value to screen.

cout << "Contents of board[0] are:#" << board[0] << "#";

The # will make it clear to you what is in board[0] if there are spaces or other difficult to judge characters.
Last edited on
It outputs a space, as it is supposed to!
It outputs a space, as it is supposed to!


Not quite.

At that point, the contents of board[0] (which is the board object inside the peg_t object, which is not the board object you previously set to contain spaces) is the number zero (or possibly some random number, depending on your system), which unfortunately can print out as a space. The actual space character you are comparing it to, ' ', has the numerical value 32.

Try this and you'll see the difference.

1
2
3
4
5
  case 11:
                      cout << "Case 11: " << "board[0] =#" << board[0] << "#" << endl;
                      cout << int(board[0]) <<endl;
                      board[0] = ' ';
                      cout << int(board[0]);


You've got three board objects in this; one you made like this - Board_t Board; - and the one in each peg_t object, User and Comp.

Did you really want three boards? I expect you wanted only one.
Last edited on
Well yes, I did wan't only one Board array. I guess I misunderstood the concept of Inheritance!
So if I want to access the board in the Board_t class, can I do it by Board_t::board[0]?
No, by Board.board[0]

The name of your actual created object is Board. Board_t is the name of the kind of thing it is, but there's no actual created object here named Board_t.
Topic archived. No new replies allowed.