C++ Example of the simplest Tic-Tac-Toe Program?

Coldkilla

Diamond Member
Oct 7, 2004
3,944
0
71
I'm really trying to get the hang of programming and I've just now started to get the hang of the basics. When I say basics I mean basics. I was wondering if anyone knows of a prewritten program or would mind making a compilable C++ Tic-Tac-Toe program so I can learn by example? Perhaps some notes in the program as to what does what?

It's been confusing trying to think of ways on how to do this, but I don't want to give up. So, please... if you have a little time to spare.
 

Aikouka

Lifer
Nov 27, 2001
30,383
912
126
Well, tell me this... you mentioned you were trying to think of ways to do this. What aspects are you stuck on? It's quite important to lay your idea down and realize where your holes are before you begin and try to fix those holes.

So, I'd say list out how you'd go about creating this tic-tac-toe game (i.e. list steps, such as "get p1 input" "place in array" "redraw board" etc) and if you have any issues with how to do this, just ask.
 

tfinch2

Lifer
Feb 3, 2004
22,114
1
0
First you must think about the data structure you're going to use to hold the board, how you're going to check for wins, etc. You can do all that without knowing how to code in C++.
 

jman19

Lifer
Nov 3, 2000
11,225
664
126
Another thing to consider is if you plan on this being a two-player game only, or one you can play against the computer. If it is the latter, you'll need to consider how to make the computer play "intelligently" against the player.
 

Coldkilla

Diamond Member
Oct 7, 2004
3,944
0
71
Good point. When I have time I will try and show you how I think you would do it. However it's probably all screwed up.

I'm going to go with Two Human Players. I don't want to throw in intelligence yet.
 

hans007

Lifer
Feb 1, 2000
20,212
18
81
if you just do it with 2 human players its a piece of cake.

the easiest way is something like this..


int board[3][3];

bool checkifsomeonewon(int board[][])

{
return won;
}

while(!checkifsomeonewon())
{

ask for board input, display board perhaps,



}

im not gonna fill in the function , or the input part, but its trivially easy.