You can still use numbers ( but not coords) for user input.
if the board looks like this:
123
456
789
you can use integer division and remainder to calc the row & col. Subtract 1 from what they enter, integer division by 3 gives the row, the remainder is the col. This is easier than using chars I think.
To check for a win, you check the rows, cols and diagonals. This is easily done with nested for loops - for example to check one of the diagonals, check 0,0 1,1 2,2
I would have a CheckWin function, with code separated into check rows, check cols, check diagonals. This would cut down your code because lines 185 to 200 is very similar to lines 235 to 251. The same could be achieved with one CheckWin function that takes a player as an argument, and returns a bool.
You could also make use of the std::toupper function to avoid testing variables twice to cover upper or lower case:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <locale>
char player1;
cin >> player1;
player1 = std::toupper(player1);
if (player1 == 'O') {
//your code
}
else if (player1 == 'X' ) {
//your code
}
else {
//your code
}
| |
Also note that when the variable is an integral type ( including chars), you can use a switch statement instead of a load of else if clauses.
You need to make more use of functions - the game function has 160 lines which is too much.
Hope all goes well.