Article feedback

Hello!

I would like to receive feedback from my first article (take it easy!), which is a Tic-Tac-Toe!

The C++forum does not allow feedback, so i would appreciate some feedback.
What do you think of the source code and what can be improved?
This is the article link: http://www.cplusplus.com/articles/1v07M4Gy/


So many loops and if statements (overwhelming!!!:p) but it looks really good :) good job i like it.
Line 165, tolower() doesn't change the argument, it returns its lowercase letter.

The function validatePosition() could be rewritten. Something like
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
bool validatePosition (char pos, char mt [l][c], bool player1)
{
    // converts numerical character to number, in range -1/8 instead of 0/9
    int position = pos - '0' - 1; 
    if(position == -1)
    position = 0; // quick fix -- should be done better
    int row = position / COLUMN_COUNT;
    int col = position % COLUMN_COUNT;

    if (mt [row][col] != '?')
    {
        cout << "Position already used, type another position." << endl;
    }
    else
    {
        if (player1 == true)
            mt [row][col] = 'X';
        else
            mt [row][col] = 'O';
        return true;
    }
    return false;
}

but it would be better to use directly an integer to input the position.

I'd use more descriptive names: gameType == SINGLEPLAYER // MULTIPLAYER // SINGLEPLAYER_HARD instead of op == 1// 2 // 3 .
And it doesn't look like you can have op == 3.

I just skimmed through it, but since there isn't much of an explanation of what you're doing I see it more like a code sample, and in this case I would polish it some more rather than use clear and simple logic to help beginners. But that's just me.

I don't like much that it's windows only.
Last edited on
Topic archived. No new replies allowed.