You could greatly simplify your program if you used arrays instead of numbered variables. You'll want to use 2-dimensional arrays, as it will make your program easier to write. Since it's a 3x3 grid, declare it like that:
bool myGrid[3][3];
You'll want to create a seperate function for drawing the grid, seeing that you're going to need to call it multiple times.
You might also want to consider posting a question so we can have an idea what you're having problems with...
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
lol!!!
first off i don't know how to do any of that stuff, is there like a tutorial for that?
well, not really a tutorial just the part about arrays and and
bool Mygrid[3]x[3]
Actually scratch that. It should be char, not bool, since there's going to be 3 possible values:Empty
an 'X'
an 'O'
The 2 dimensional array is used because there's 2 dimensions: up/down, and left/right. Let me show you some visualization...
[0] [1] [2]
[0]char char char
[1]char char char
[2]char char char
Does this not look familiar to this?
|| || ||
x
_____________
|| || ||
x
_____________
|| || || x
(Perhaps a bad diagram, but hopefully it gets my point across.)
Then if the user wants to put an X in, say coordinates (2,3), you could write something like this:
myGrid[1][2] = 'X';
Notice that it's (1,2) instead of (2,3) because C++ arrays start at 0.
You'd also have to do error checking, because that space could already be occupied by a X/O. But it was just an example.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
A algorithm for the game can be found here though not in C but still will serve its purpose of pointing you in the right direction.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
hmm, i'm not really sure what you mean by "case"(i haven't learned that yet, but i will "google" it), but i hope you know that this will be computer versus player...
Consider first writing the program for 2-player mode, as that will be far easier to code and debug.
Once you have the framework working, you can proceed to write the artifical intelligence that the computer needs in order to play. Remember, always work your program up in steps - all at once means that there's too many bugs to find and fix, taking far longer than if you had simply solved little bugs one at a time.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
Clinton Portis
Practically a Posting Shark
833 posts since Oct 2005
Reputation Points: 237
Solved Threads: 118