| | |
HELP!!! Tic-tac-toe game!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2007
Posts: 44
Reputation:
Solved Threads: 0
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)..
he is what i got so far.. PLEASE help it out!(i will update the code sometimes)..
C++ Syntax (Toggle Plain Text)
#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; }
--
The Statement BELOW is FALSE.
-\/-/\-\/-/\-\/-/\-\/-/\-\/-/\-\/-/\-\/-
The Statement ABOVE is TRUE.
The Statement BELOW is FALSE.
-\/-/\-\/-/\-\/-/\-\/-/\-\/-/\-\/-/\-\/-
The Statement ABOVE is TRUE.
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:
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...
C++ Syntax (Toggle Plain Text)
bool myGrid[3][3];
You might also want to consider posting a question so we can have an idea what you're having problems with...
"Technological progress is like an axe in the hands of a pathological criminal."
•
•
Join Date: Jan 2007
Posts: 44
Reputation:
Solved Threads: 0
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
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
C++ Syntax (Toggle Plain Text)
bool Mygrid[3]x[3]
Last edited by lotsofsloths; Feb 14th, 2007 at 9:22 pm.
--
The Statement BELOW is FALSE.
-\/-/\-\/-/\-\/-/\-\/-/\-\/-/\-\/-/\-\/-
The Statement ABOVE is TRUE.
The Statement BELOW is FALSE.
-\/-/\-\/-/\-\/-/\-\/-/\-\/-/\-\/-/\-\/-
The Statement ABOVE is TRUE.
•
•
•
•
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
C++ Syntax (Toggle Plain Text)
bool Mygrid[3]x[3]
- Empty
- an 'X'
- an 'O'
C++ Syntax (Toggle Plain Text)
[0] [1] [2] [0]char char char [1]char char char [2]char char char
C++ Syntax (Toggle Plain Text)
|| || || x _____________ || || || x _____________ || || || x
Then if the user wants to put an X in, say coordinates (2,3), you could write something like this:
C++ Syntax (Toggle Plain Text)
myGrid[1][2] = 'X';
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.
Last edited by John A; Feb 14th, 2007 at 9:48 pm.
"Technological progress is like an axe in the hands of a pathological criminal."
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 don't accept change; I don't deserve to live.
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
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
Last edited by Lazaro Claiborn; Feb 15th, 2007 at 5:00 am.
•
•
•
•
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...
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.
"Technological progress is like an axe in the hands of a pathological criminal."
![]() |
Similar Threads
- Tic-Tac-Toe (C++)
- Tic-Tac-Toe Game (Visual Basic 4 / 5 / 6)
- Tic-Tac-Toe Game - Need some information or help (C++)
- tic-tac-toe in c++ with GUI (C++)
- C++ Tic Tac Toe using classes & operator overloading (C++)
- Tic Tac Toe Homework (C++)
Other Threads in the C++ Forum
- Previous Thread: replace characters
- Next Thread: problem inserting elements in a 2D vector
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






