Introduction
Tic-tac-toe, also called noughts and crosses, hugs and kisses, and many other names, is a pencil-and-paper game for two players, O and X, who take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three respective marks in a horizontal, vertical or diagonal row wins the game. This game is won by the first player, X:
│ │ X O │ │ X O │ │ X O │ │ X O │ │ X O │ │ X O │ │ X
───┼───┼─── ───┼───┼─── ───┼───┼─── ───┼───┼─── ───┼───┼─── ───┼───┼─── ───┼───┼───
│ │ │ │ │ │ │ O │ │ O │ │ O │ O │ O │ O
───┼───┼─── ───┼───┼─── ───┼───┼─── ───┼───┼─── ───┼───┼─── ───┼───┼─── ───┼───┼───
│ │ │ │ X │ │ X │ │ X │ │ X X │ │ X X │ X │ X
Your ‘Assignment’Stage 1:
Write a simple program that will allow two ‘human’ players to play Tic-tac-toe on the screen, there is no need to determine Win, lose, or draw yet. Just make sure that the players can not put marks in places that already have marks and finish the ‘playing’ sequence when all spaces are taken.
Stage 2:
Modify your program from stage 1 to allow your program to determine Win, lose, or draw states.
Stage 3:
Modify your program from stage 2, to have the option of playing against a ‘computer’ opponent.
______________________________________ Motivation came from a posting by arrrgh.Introduction from Wikipedia
I have been trying to do this for a while, but I think what I was doing wrong, is I was trying to do step 2 and 3 before I even did step one. I will try doing it the right way!
Also how would you solve this problem. I am not really interested in the source code, but rather the methodologies behind developing software.
There are a number of approaches to problem solving for a problem like this.
My take would be to look at the problem and see how to break it down into simpler problems - so here you might decide the porblems are
1) Display the Grid
2) Display the 'pieces' on the grid
3) Determine if more pieces can be placed
4) Enter position for next piece.
For stages 2 point (3) can be extended to check for Win, Lose or Draw, and for stage 3 you can develop a (4a) wich is an computer placement.
Having done a first take on simplifying the problem, you then think about relationships between the stages - common data, functions, classes, etc.
This can then be repeated on the subtasks until you reach a point where you have something you are happy you have understood the problem and have simplified the subtasks to a point where you can code them without risking any additional interdependancies.
For a larger project, where multiple developers are involved, gettign the design to a point where you know the interdependancies before coding starts is important, as that is the point where you can portion the work out to different people, safe in the knowledge that the links between the code will be OK.
Hi, from a design standpoint I would have appraoched it differently.
I try and separate the design into three functional layers - User Interface, Core Logic and Data Storage.
This can be a good habit to get into as it makes portability easier. If you wanted to switch from consol to GUI then you only need to change the UI layer, if you wanted to add a score table (Trivial example in this case:-) then you can easily switch from text file to DB without affecting the rest of the app, etc.
In this case I would have a class to hold the state fo the board, a class to display it, etc.