Do any one have the source codes for a Naughts & Crosses Game?
If you have please send it as an email to henryjia18@yahoo.com or add it here as a comment.
Thankyou
Um... sorry to hear. However, as Duoas correctly stated, the problem shouldn't be that hard.
If you have a piece of code you'd like us to review, we'll happily do that, but we try to avoid giving out code or step-by-step solutions (for good reasons too).
If you have been learning C++ for a few months already, this should really be no problem anymore for you... Naughts & Crosses is something you normally do in your first weeks... Where exactly is your problem?
You will have to use a few functions for each thing your program does. One function to get a user's input, another to display the gameboard, another to check for a win, etc. You'll also have to keep track of whose turn it is, X or O.
BTW, you don't have to check for two in a row, just check for three in a row. That's fairly straightforward:
I think he wanted to know if there are two in a row so that the computer could act accordingly and block the user from getting three in a row on the next move.
That's also fairly straightforward, it's just that the easiest way out would require you to do more checks (think: 8 three-in-a-rows * 3 possibilities for the removal of one naught or cross per three-in-a-row = 24 possibilities).
There are two possibilities: the horizontal and the vertical.
Your code does not check all possible cases -- it finds the horizontal case and aborts, assuming that there is not other possible case.
Reconsider the code this way: you want to look for any potential three in a row. That is, it should ask the following questions, in order:
1. Is it possible for me to place my piece and have a three in a row right now? (If yes, do it.)
2. Is it possible for my opponent to place a piece and have a three in a row right now? (If yes, place my piece there.)
There are other questions you can ask if the answer to both is "no", but I'll leave it at that.
It does check every possibilities and works when the 3 by 3 square is not almost filled up but as soon as the 3 by 3 square is almost filled up, it jamms.
If it is jamming then perhaps it gets stuck in a loop somewhere. Try setting breakpoints at various places and stepping through it with a debugger to find out where in the code your problem is.
I found out how to get the program working now. There was aproblem because I forgot to get it to check if there was an empty space or not so it kept on putting an 'O' where there's already an 'O'. Thanks for the advices guys!!!