HELP!!! Tic-tac-toe game!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2007
Posts: 44
Reputation: lotsofsloths is an unknown quantity at this point 
Solved Threads: 0
lotsofsloths lotsofsloths is offline Offline
Light Poster

HELP!!! Tic-tac-toe game!

 
0
  #1
Feb 14th, 2007
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)..
  1.  
  2. #include <iostream>
  3. using namespace std;
  4. int main ()
  5. {
  6. int line1;
  7. int line2;
  8. int line3;
  9. int line4;
  10. int line5;
  11. int line6;
  12. int line7;
  13. int line8;
  14. int line9;
  15. int line10;
  16. int line11;
  17. int line12;
  18. int line13;
  19. int line14;
  20. cout << "Tic-Tac-Toe, 3 in a row!\n";
  21. cout << "I go first...\n\n\n\n\n\n\n\n";
  22. cout << " | | \n"<<line1;
  23. cout << " | | \n"<<line2;
  24. cout << " | | \n"<<line3;
  25. cout << "_________________________________\n"<<line4;
  26. cout << " | | \n"<<line5;
  27. cout << " | | \n"<<line6;
  28. cout << " | | \n"<<line7;
  29. cout << " | | \n"<<line8;
  30. cout << " | | \n"<<line9;
  31. cout << "_________________________________\n"<<line10;
  32. cout << " | | \n"<<line11;
  33. cout << " | | \n"<<line12;
  34. cout << " | | \n"<<line13;
  35. cout << " | | \n"<<line14;
  36. cout << "\n\n\n\n\n\n\n\n\n\n\n";
  37. cout << " | | \n"<<line1;
  38. cout << " | | \n"<<line2;
  39. cout << " | | \n"<<line3;
  40. cout << "_________________________________\n"<<line4;
  41. cout << " | | \n"<<line5;
  42. cout << " | | \n"<<line6;
  43. cout << " | _\/_ | \n"<<line7;
  44. cout << " | /\ | \n"<<line8;
  45. cout << " | | \n"<<line9;
  46. cout << "_________________________________\n"<<line10;
  47. cout << " | | \n"<<line11;
  48. cout << " | | \n"<<line12;
  49. cout << " | | \n"<<line13;
  50. cout << " | | \n"<<line14;
  51. return 0;
  52. }

--
The Statement BELOW is FALSE.
-\/-/\-\/-/\-\/-/\-\/-/\-\/-/\-\/-/\-\/-
The Statement ABOVE is TRUE.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: HELP!!! Tic-tac-toe game!

 
0
  #2
Feb 14th, 2007
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:
  1. 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...
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 44
Reputation: lotsofsloths is an unknown quantity at this point 
Solved Threads: 0
lotsofsloths lotsofsloths is offline Offline
Light Poster

Re: HELP!!! Tic-tac-toe game!

 
0
  #3
Feb 14th, 2007
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
  1. 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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: HELP!!! Tic-tac-toe game!

 
0
  #4
Feb 14th, 2007
Originally Posted by lotsofsloths View Post
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
  1. 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...
  1. [0] [1] [2]
  2.  
  3. [0]char char char
  4.  
  5. [1]char char char
  6.  
  7. [2]char char char
Does this not look familiar to this?
  1. || || ||
  2. x
  3. _____________
  4. || || ||
  5. x
  6. _____________
  7. || || || 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:
  1. 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.
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."
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 44
Reputation: lotsofsloths is an unknown quantity at this point 
Solved Threads: 0
lotsofsloths lotsofsloths is offline Offline
Light Poster

Re: HELP!!! Tic-tac-toe game!

 
0
  #5
Feb 14th, 2007
could ya help me how that would look in code?
--
The Statement BELOW is FALSE.
-\/-/\-\/-/\-\/-/\-\/-/\-\/-/\-\/-/\-\/-
The Statement ABOVE is TRUE.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,609
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: HELP!!! Tic-tac-toe game!

 
0
  #6
Feb 14th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 171
Reputation: Lazaro Claiborn is an unknown quantity at this point 
Solved Threads: 13
Lazaro Claiborn's Avatar
Lazaro Claiborn Lazaro Claiborn is offline Offline
Junior Poster

Re: HELP!!! Tic-tac-toe game!

 
0
  #7
Feb 15th, 2007
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
Last edited by Lazaro Claiborn; Feb 15th, 2007 at 5:00 am.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 44
Reputation: lotsofsloths is an unknown quantity at this point 
Solved Threads: 0
lotsofsloths lotsofsloths is offline Offline
Light Poster

Re: HELP!!! Tic-tac-toe game!

 
0
  #8
Feb 15th, 2007
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...
--
The Statement BELOW is FALSE.
-\/-/\-\/-/\-\/-/\-\/-/\-\/-/\-\/-/\-\/-
The Statement ABOVE is TRUE.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 44
Reputation: lotsofsloths is an unknown quantity at this point 
Solved Threads: 0
lotsofsloths lotsofsloths is offline Offline
Light Poster

Re: HELP!!! Tic-tac-toe game!

 
0
  #9
Feb 15th, 2007
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.
--
The Statement BELOW is FALSE.
-\/-/\-\/-/\-\/-/\-\/-/\-\/-/\-\/-/\-\/-
The Statement ABOVE is TRUE.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: HELP!!! Tic-tac-toe game!

 
0
  #10
Feb 15th, 2007
Originally Posted by lotsofsloths View Post
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.
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC