hey guys, i am writing a program for tictactoe n I have this is the board i have got to work on. I have the board display working perfectly already.
The problem is that, players should enter a move by typing in a letter followed by a number, e.g. "a1", as in standard chess notation.
Sample game in progress (with BOARD_SIZE == 4):
....a... b...c...d
..+--+--+--+--+
4.|...|...|...|...|.4
..+--+--+--+--+
3.|.X|.X|.O|...|.3
..+--+--+--+--+
2.|...|.O|...|...|.2
..+--+--+--+--+
1.|...|...|...|...|.1
..+--+--+--+--+
....a...b...c...d
(sorry, i have to use dots instead of spaces or the board prints badly here).
I have tried to use strings to check the positions cos I used a 2D array like char[rows][columns]; So far I have got this code written to check for player input, but I have doubts about its functioning.
//function to get user input.
int playgame(string player1move, string player2move)
{
// find out which move the player wants to make
cout << "Player1, make your move. Enter a move by typing in a letter followed by a number, e.g. \"a1\".\n";
getline(cin, player1move);
//statement to check validity of input;
if((!(isalpha(player1move[0]))) || (!(isdigit(player1move[1]))) || player1move.lenght > 2 || (player1move[1] >= columns || (code to check if alphabet entered is valid ie, displayed on the board.)
{
cout << "Please enter your choice again.
getline(cin, player1move);
}
Then I have to correspond the input to the board space and print out an X or O for the player. I am a little stuck on this part and I would appreciate any help offered either to better this code or from a whole new approach. Thanks guys.