ok, i am going to *attempt* to make a tic-tac-toe kinda game...
he is what i got so far.. PLEASE help it out!(i will update the code sometimes)..

#include <iostream>
using namespace std;
int main ()
{
int line1;
int line2;
int line3;
int line4;
int line5;
int line6;
int line7;
int line8;
int line9;
int line10;
int line11;
int line12;
int line13;
int line14;
cout << "Tic-Tac-Toe, 3 in a row!\n";
cout << "I go first...\n\n\n\n\n\n\n\n";
cout << " | | \n"<<line1;
cout << " | | \n"<<line2;
cout << " | | \n"<<line3;
cout << "_________________________________\n"<<line4;
cout << " | | \n"<<line5;
cout << " | | \n"<<line6;
cout << " | | \n"<<line7;
cout << " | | \n"<<line8;
cout << " | | \n"<<line9;
cout << "_________________________________\n"<<line10;
cout << " | | \n"<<line11;
cout << " | | \n"<<line12;
cout << " | | \n"<<line13;
cout << " | | \n"<<line14;
cout << "\n\n\n\n\n\n\n\n\n\n\n";
cout << " | | \n"<<line1;
cout << " | | \n"<<line2;
cout << " | | \n"<<line3;
cout << "_________________________________\n"<<line4;
cout << " | | \n"<<line5;
cout << " | | \n"<<line6;
cout << " | _\/_ | \n"<<line7;
cout << " | /\ | \n"<<line8;
cout << " | | \n"<<line9;
cout << "_________________________________\n"<<line10;
cout << " | | \n"<<line11;
cout << " | | \n"<<line12;
cout << " | | \n"<<line13;
cout << " | | \n"<<line14;
return 0;
}

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...

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]

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.

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.

I'm going to try to keep this reply as short as possible so I will not quote your posting. I've been involved in writing game AIs using nerual networks and/or finite state machines and/or etc., so for future thought, you might want to consider learning and writing a simple game AI so you don't have to play yourself or move while someone else goes.

I an idea would be to write a function with a static 3 X 3 grid, as aforementioned, and have the function take two parameters representing the x and y coordiantes of where top place the X or O. Also, you could use a constant to define an X and O for player 1 and player 2. The function would simply clear the terminal window then rewrite adding an X or O to the corrdinates specified by the passed parameters.

Then you'd simply write a function algorithm that'd recognize all the possible winning situations and scan before return from above function.

Here is some simple psuedo code:
define constant player one to X and player two to O
do
get input that'd represent a specific section or coordinate (i.e A for the first square)
switch the input
case A 1 x 1
case B 1 x 2
case C 1 x 3....
put the case coordinate into two variables
while the return value of the write function passing the previous case coord variables and a flag that says what player has moved, keep looping

For the two functions, you'd just write them so that the write function takes three parameters (i.e x, y, flag) and make sure the 3 x 3 array withing the function block is declared as static. Then write a scanning function that takes a character array paremeter, scans it to check for winning conditions then if a win condition is encountered, call another function printing whose the winner, afterwhich, the write function would return 1 so to break the loop.

Just an idea and I'm sure there are other ways, as usual.

Good luck, LamaBot

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...

i know this will take alot of time to make(to make the computer input an x or 0 if someone goes somewhere...
but trust me, i have alot of free time.

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.

ok, i'll try

Indeed, structured programming is good. However, since you don't know what a case and therefore a switch conditional statement is, I suggest you learn the basics. Here is my website http://techspire.podzone.net, if you can't reach it then try any of the following:

http://www.cprogramming.com/tutorial.html
http://www.cplusplus.com/doc/tutorial/
http://intro2cpp.tripod.com/
http://www.4p8.com/eric.brasseur/cppcen.html
http://www.astahost.com/info.php/basic-c-language_t2064.html

Once you've learned the basics you'll be equipped with the knowledge that'll allow you to be creative and maybe write some amazing code. As for your tic-tac-toe program, you can either write it while you're learning or you can write it after, your choice :) Also, you might want to LATER learn about structured programming but in my opinion, learn the basics and write the tic-tac-toe program first.

Good luck, LamaBot

Kudos Clinton.... Also, there is a posting titled "Tic-Tac-Toe - Need information or ideas" in the same forum this thread was started in. The re-written program functions correctly but has some disfunctionality relative to the previous posted program, which with you can simply touch up, andalso might be of some use to someone learning or etc....

Here is a link to it: http://www.daniweb.com/techtalkforums/thread70107.html

This article has been dead for over six months. Start a new discussion instead.