Tic Tac Toe...Help getting started!

This is a discussion on Tic Tac Toe...Help getting started! within the C++ Programming forums, part of the General Programming Boards category; Hey guys, I'm still in the beginning stages of learning C++ and my newest assignment is to write a two ...

Tic Tac Toe...Help getting started!

Hey guys, I'm still in the beginning stages of learning C++ and my newest assignment is to write a two player tic tac toe game. I am not asking you to write the program for me, I would just like you help me get started. Kind of like an outline for the program. What kind and how many functions should I be using?

I'd probably use at least these functions:
main() -- obvious
initializeBoard() -- set up the board to an empty state
displayBoard() -- output the current state of the board
acceptMove() -- input the position to mark
testForWin() -- check the board to see if there was a win

Basic outline:

Code:

Initilaize the board
Start a loop
display the board
input a position to mark
mark the position entered
test for a win
if a win, break out of loop
set up for the next player
end of loop
display the board
display the outcome

I can remember creating a noughts and crosses game using Pascal during my A-levels (a long time ago ). There are alot of ways to approach the problem, but my solution took advantage of the fact that you can arrange the numbers 1-9 on a 3x3 board to create the sum of 15 in all directions.

Code:

2 9 4
7 5 3
6 1 8

I'm pretty certain there are better ways than this in C++. Using this method, you have to check that the sum to 15 is made up of 3 numbers, no more or less (eg, 9+6 or 1+2+8+4)

I'm terrible at programming right now....can some one please give me some more insight on getting started. I don't even know where to begin. I have a lot of trouble with the structure but I can handle the details in between!

Please help me out!

Once again, I'm not asking you to do the assignment for me, but I would love it if some one could please give me a basic walkthrough or suggestions, as I'm having a lot of trouble in this course!

> please give me a basic walkthrough or suggestions,
You're just being lame man, that page you posted is knee-deep in suggestions if you'd just go and actually read the damn thing. WaltP pretty much gave you the answer without actually posting the solution.

This is program #12, what on earth did you do for programs 1 to 11?
I assume you made at least some effort to solve them yourself, or did you wander from board to board whining on about how hard they were as well. If you did, then you've already failed and helping you is pointless.

I mean, at least make some effort - how hard can it be to draw

Code:

| |
------
| |
------
| |

Or just print

Code:

Welcome to Tic-Tac-Toe!
Three in a row wins!
1).Play a game
2).Quit
Please make a selection:

> as I'm having a lot of trouble in this course!
Perhaps it's time to consider a change of course then, because this seems pretty spoon-feedy for a 6th assignment.

Thanks for being a total douche about it Salem...I'm sure you picked up everything right away while learning C++ as well. I came here for help, not for someone (especially with that high of a post count) to sit here and flame my post. How am I to complete an assignment when I do not know where to begin?

Anyway, thanks everyone for your suggestions.

One question, I do not understand how to incorporate positions on board into the array? (We just got a brief run-down on arrays, so I am still a bit confused).

Thanks for being a total douche about it Salem...I'm sure you picked up everything right away while learning C++ as well. I came here for help, not for someone (especially with that high of a post count) to sit here and flame my post. How am I to complete an assignment when I do not know where to begin?

Anyway, thanks everyone for your suggestions.

One question, I do not understand how to incorporate positions on board into the array? (We just got a brief run-down on arrays, so I am still a bit confused).

Advice: When a God speaketh, ye should listen.
EDIT: Maybe that should've been shall, not should. Meh.

> I am not asking you to write the program for me
Get off your ........ing arse then and start demonstrating that you can do something about it then.

> not for someone (especially with that high of a post count) to sit here and flame my post.
Because your post bloody well deserved it.
If you had any clue whatsoever, you'd find that I provide a lot of useful help to those who put some effort in themselves. All you seem to have done is post a URL to the homework and whine about how hard it all is.

> How am I to complete an assignment when I do not know where to begin?
Gee, how many times do you need telling?

> I do not understand how to incorporate positions on board into the array?
Now this is more like it, a specific question about a specific problem. If this is the only thing holding you back, then why didn't you ask it in the first place?
Unless you state up front (by posting some code for example) a demonstration of the bits you can do and the bits you can't do (or are confused about), then stuff like your first post is just going to get flamed every single time.
And to answer your question, study how pos / 3 and pos % 3 may help you figure out grid coordinates for your game board.

@the_lumin8or:
Stop wasting our time. We're not some C++ Noobs Anonymous help/care group. This forum is for specific problems and errors, not for teaching you how to do things. Go ask your professor/teacher/lecturer if you don't know where to start. If you didn't listen in class, well go f*** yer @$$, we're not gonna teach you.

If you have a problem, post it in black+white, including code. Then explain your problem nicely. Otherwise don't expect any help at all.