Tic-Tac-Toe Game...
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]
http://www.cplusplus.com/doc/tutorial/tut3-1.html
Scroll down to multidimentional arrays. Or, examine this:
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.
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!
btw, your code looks so messy... take a look at this:
http://www.geocities.com/antigatez/pimplesttt.zip
only 412 lines for ya!
...that doesn't help much. But I rewrote the code. Trying a different way now... I can't get the AI to work....
[edited by - DarkWhoppy on July 27, 2003 6:21:07 PM]
[edited by - DarkWhoppy on July 28, 2003 6:03:41 PM]
#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]
code still messy (imo)...
why don''t you drop the two dimension array for the board and use board[8] instead?
why don''t you drop the two dimension array for the board and use board[8] instead?
Why should he? If it's a 2D game board, model it as a 2D array...
Makes sense to me.
Also, seriously consider
instead of
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]
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.
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.
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
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
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!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement