Lines in tic-tac-toe

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

Recommended Posts

About how many lines of code do you think a tic-tac-toe game should have if it's written in the C language.

Share on other sites
Assuming in console mode, probably a few hundred. Why does it matter?

Share on other sites
yea in console mode. I want to make sure I don't have any "lazy code" and how much is a few hundred, 300?

Share on other sites
I'd guess about 300 or 400, yeah. What do you mean "lazy code"?
The number of lines of code in an application really doesn't matter. You could probably write tic-tac-toe in about 50 lines, but it would be horrible. Or you could write it in 1000 lines, with loads of flashy (console mode) graphics.

Share on other sites
by lazy code I mean not having good solid algorithms.

Share on other sites
Well, the number of lines of code won't really help you judge that. If you write down an algorithm first, and try to stick to it when coding, that'll help. E.g.
Draw board   Draw lines   Draw X's   Draw O'sGet Input   Ask player for board position (1-9)   Get position   Check position is valid
Etc etc.

Share on other sites
mine is kinda more flashy than that. It actually uses windows!!! console windows using the ncurses library that is.

BTW before starting a project like tic-tac-toe would you first plan and then start coding?

Share on other sites
Quote:
 Original post by subfloodBTW before starting a project like tic-tac-toe would you first plan and then start coding?

The most important thing is ofcourse to figure out the maximum lines of code that you allow!!!!

/MindWipe

Share on other sites
I wrote mine in 155, including comments. So 300 should be plenty.

The difference with a game like tic-tac-toe is that it is very easy to plan. Infact, Evil already planned it for you. But writing out how you want your program to run is very crucial for large scale projects. Its good to get the practice with small ones, and normally leads to more legible, more constructed, and faster programs.

Share on other sites
It takes as many lines as it takes, really. The way to tell if you wrote too much is to look for duplication. And if you find some, fix it!

• 18
• 29
• 11
• 21
• 16