Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
The notepad contains all possible combinations of tic-tac-toe (255 168 possibilities). The requirement is to illustrate all possible moves of every game in a visual format (more than 1 million images will be generated as a result).

To complete the task the following are provided:
1. 3x3 grid
2. X
3. O

Requirements:
1. Image size of 720x720
2. The bottom right corner must contain numbers of a move and of a game underneath
3. The image of the game outcome must contain a “winning line” and the game result in a bottom right corner

What I have tried:

Please, help with the following task
Posted
Updated 9-Jun-21 6:52am
Comments
Richard MacCutchan 9-Jun-21 8:34am    
Help how?
CHill60 9-Jun-21 8:43am    
What have you tried? What is the problem?
Member 15235966 9-Jun-21 8:56am    
I'm new to this. Please tell me how you see the logic of complete this task and i'll try to complete it
CHill60 9-Jun-21 8:58am    
I would point you towards the article that OriginalGriff has referenced in Solution 1. If you are still struggling then you need to discuss this with your tutor. We can only help with specific problems in this forum and nor will we do the work for you

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
This is not a problem for a beginner. Here's how I would approach it.

Build a tree of positions. Each of the cells in a position has three possible values: X, O, or empty. The root position is an empty grid. If X goes first, there are 9 possible moves (I'm assuming you don't have to bother with rotations and reflections to eliminate "identical" positions).

Now we have the second level of the tree (the one below the starting position), which has 9 positions. Each of those positions has 8 moves for O, resulting in 72 positions at the third level. The fourth level will have 72x7=504 positions, and the fifth level will have 504x6=3024 positions.

Once we reach the fifth level, X will win some games. When a game has been won, you no longer generate moves from that position, which means that the ninth level of the tree will have less than 9! positions.

If you number each position, you can follow a game through the tree and display its "number" and the moves up to that point. Some positions can be reached by different move orders, so you need to record the moves to display them.

When a game has been won, record the winning move against the parent node in the tree so that you can display it if that position is reached. This gets complicated, however, because a winning line can begin on a player's previous move. Take this position, with X to move:
XO-
O--
X--
If X plays in the center, it's a winning line, no matter what O does:
XO-
OX-
X--
In the tree, O has 4 possible moves before X wins. Sometimes the win comes from playing in the upper right, sometimes in the lower right, and on one of O's moves, X will even have a choice! But the point is that any O move allows X to win. When this occurs, the previous position (the first position above) should also show the winning move. This is how databases of chess endings are created, which allows a program to play perfectly once a position in the database is reached.
 
Share this answer
 
Quote:
I'm new to this. Please tell me how you see the logic of complete this task and i'll try to complete it

Obviously, your level do not match this task level, and we have no way to teach you in the scope of this little textbox.
find some tutorials and do every exercise to get started.
Learn one or more analyze methods, E.W. Djikstra/N. Wirth Stepwize Refinement/top-Down method is a good start.
Structured Programming.pdf[^]
https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design[^]
https://en.wikipedia.org/wiki/Structured_programming[^]
https://en.wikipedia.org/wiki/Edsger_W._Dijkstra[^]
https://www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF[^]
Program Development by Stepwise Refinement[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900