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/
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';
returntrue;
}
returnfalse;
}
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.