Tic-Tac-Toe Game...

Started by
19 comments, last by DarkWhoppy 20 years, 8 months ago
I am trying to figure out how to use a 2D array. Just doing this little Tic-Tac-Toe game to help for me to see how they work in action. But im kinda stuck...Can someone point me in the right direction? (i dont wanna start a project and now finish it ) Half of the code I've been changing around...but I can't seem to get my 2D array to work. -----Code Removed by ME!------- [edited by - DarkWhoppy on July 27, 2003 6:21:55 PM]
Visit the 3DHangout
Advertisement
http://www.cplusplus.com/doc/tutorial/tut3-1.html

Scroll down to multidimentional arrays. Or, examine this:

char board[3][3];  // a 3 x 3 arrayif (  (''X'' == board[0][0] && ''X'' == board[1][1] && ''X'' == board[2][2])   || (''X'' == board[0][0] && ''X'' == board[0][1] && ''X'' == board[0][2])   || (all the other cases for an X win)   ) {      // X won, so do stuff} 

2D arrays aren''t terribly complicated.

Also, the result of a winning condition for either player is always the same, so you could shorten/simplify your code a lot by lumping all the winning cases for a given player together with OR.
true...
btw, your code looks so messy... take a look at this:
http://www.geocities.com/antigatez/pimplesttt.zip
only 412 lines for ya!
---Current project - Duck Hunt 2: Free at Last!http://www.duckhunt2.cjb.net
...that doesn't help much. But I rewrote the code. Trying a different way now... I can't get the AI to work....

#include <iostream>#include <string>#include <stdlib.h>using namespace std;---Code Removed by ME!!---[edited by - DarkWhoppy on July 27, 2003 6:20:05 PM]    


[edited by - DarkWhoppy on July 27, 2003 6:21:07 PM]

[edited by - DarkWhoppy on July 28, 2003 6:03:41 PM]
Visit the 3DHangout
code still messy (imo)...
why don''t you drop the two dimension array for the board and use board[8] instead?
---Current project - Duck Hunt 2: Free at Last!http://www.duckhunt2.cjb.net
Why should he? If it's a 2D game board, model it as a 2D array...
Makes sense to me.

Also, seriously consider
if ('0' == Board[0][0]) { ... }  

instead of
if (Board[0][0] == '0') { ... }  

so that if you miss an = , you get a compile-time error instead of a run-time error or unexpected results.

Edit: He'd at least want to use board[9] over board[8], now that I think of it...

[edited by - Geoff the Medio on July 27, 2003 12:56:13 AM]
I don''t know if this is a dumb question but......if you use if statements for every possible move in tic tac toe, thats not considered AI right? because it will do the same move over and over.
----Me: So do you know any computer languages?Friend: Ummm....yeah, I used to know l337 talk.Me: ok....
quote:Original post by pimple
true...
btw, your code looks so messy... take a look at this:
http://www.geocities.com/antigatez/pimplesttt.zip
only 412 lines for ya!


That seems like a lot, I''m going to see if I can''t do better. Post back later.

quote:Original post by TheOne1
I don''t know if this is a dumb question but......if you use if statements for every possible move in tic tac toe, thats not considered AI right? because it will do the same move over and over.


You can call pretty much whatever you want AI. It doesn''t matter how it comes up with the solutions.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
I was thinking of using

num = rand() 6 + 3;

and some IF''s to chose the computers places for the ''O''. And if its taken then redo the entire function until it finds an open place....then when thats done call another function to check the board to see if anyone has 3 X''s or O''s in a row :D
Visit the 3DHangout
quote:
That seems like a lot, I''m going to see if I can''t do better. Post back later.


well, it''s more about QUALITY... if you actually play my game, you''ll see how effective those 412 lines really are XD

anyhoo, keep up the good work!

---Current project - Duck Hunt 2: Free at Last!http://www.duckhunt2.cjb.net

This topic is closed to new replies.

Advertisement