Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

DarkWhoppy

Tic-Tac-Toe Game...

This topic is 5468 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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 array

if ( (''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.

Share this post


Link to post
Share on other sites
true...
btw, your code looks so messy... take a look at this:
http://www.geocities.com/antigatez/pimplesttt.zip
only 412 lines for ya!

Share this post


Link to post
Share on other sites
...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]

Share this post


Link to post
Share on other sites
code still messy (imo)...
why don''t you drop the two dimension array for the board and use board[8] instead?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!