Hi guys, I posted a thing earlier about help on a tic tac toe program. I am posting this because its as if I am not able to apply any of the information Ive learned and I dont know what to do. I go through the tutorials on this site until they make sense and I grasp the concept. But I cant apply any of them to save my life. I have no idea how to make this tic tac toe program, Ive been looking online for hours, everything Ive come across makes absolutely no sense. Should I buy a tutorial book or something?
A good idea may be to think logically about how a tic tac toe game works. Think, you first draw a grid... okay make a function for that.
Then X chooses where to go, make a function for that.
Then you check if someone has won, make a function for that.
Then O chooses where to go, make a function for that.
Then you check if someone has won, make a function for that.
Repeat in a loop until someone has won.
Start your program off there and then start filling in the functions.
well I just got to the classes section but I dont understand them at all. So I have the board printed in a function and I also have two global arrays (1-9). One of the arrays is with pointers.
Ok, looking at what you have and where you can go from there:
A loop, where the player inputs the number representing the slot. If they enter an available slot, you assign that character to the slot through the pointer:
*pointer[player_input] = character;
You'll need to validate that the input slot is:
1. Within the bounds of 1-9. Array indexing starts at zero, so any number input would need 1 subtracted from it before bounds checking.
2. Not already taken. Simply look at the pointer to see if it contains an X or O. If it does, tell the player to try again.
There will be nine successful inputs before the board is filled up and you check for a winner. Since there must be three successive Xs or Os in any row, col or along one of the two diagonals, you can simply compare using an if statement to see if the contents of those slots are equal to each other. Like if( a == b && b == c), then you know a == c also.