TIC - TAC - TOE??

For
Last edited on
I would suggest you null out the game board so you can have a single function to check/set the board. Something like:

1
2
3
4
5
6
7
8
9
10
11
bool try_move(int spot, char token) // spot is the board index, token is 'X' or 'O'
{
  if(set[spot]) // not NULL, already taken
  {
    cout << "Spot taken.  Choose another." << endl;
  } else { // spot is NULL so open for the taking
    set[spot] = token;
    return true;
  }
  return false;
}
make it smaller and readable first:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void playerx()
{
            cout << "What spot would you like Player 1? : ";
            cin >> spot;
            cout << endl;

            if(set[spot-1]=='O'){
                    cout << "Spot taken. Choose another.";
                    playero();
            }
            if(set[spot-1]=='X'){
                   cout << "Spot taken. Choose another.";
                   playero();
            }
            if(set[spot-1]!='X' && set[spot-1]!='O')
            {
                 set[spot-1]='X';
            }
}


Btw.. there's a lot wrong with this..

for example:

1
2
void playeroo()
{playero();}


why not just call playero() ?? playeroo() is not needed.
Last edited on
Thank you Jikax! That helped a lot! :) Unsure what "null" is..

Yes I realize that ha... I was trying to do something ,and it didn't work.. but I just kept it tehre.
Last edited on
I don't think Texan40 really understood what you ment...
But is a pointer to nothing..
Last edited on
Topic archived. No new replies allowed.