Help taking on more advanced problems.

Started by
10 comments, last by NotAYakk 17 years, 6 months ago
Hello, I have recently found myself in a rut with my coding skills. I can pretty much write up programs for simple type problems (basic searching, sorting, some basic games such as guessing games and hangman, projectile motion simulations, etc.) without any sort of trouble at all. However, I am having diffuculty progressing beyond this level. For example, I am trying to write a progam the reads a list of words from a file and creates a word search puzzle from them. I am having a great amount of diffuculting solving this problem, and am even unsure of the approach to take. Another problem I have run into is creating AI for a Tic-Tac-Toe game. I have yet to figure out a really rigorous way to have the computer play so that it always draws against a competent player (or against itself, for that matter). Overall, I am having difficulty formulating these larger into simple, clean programs (or any type of program, for that matter. Any suggestions on how to escape this rut? Thanks!
Advertisement
I don't have an aproach to suggest for the first problem. But in general, you have to think, how would you do it without the computer, then teach the computer how to do that.

For Tic Tac Toe, the aproach should be the same. If you play enough tic tack toe, you will quickly discover that tbere is a stratagy that will always lead to a win or draw. Just goodle tic tac toe and play against the computer a few times.
I'm still stuck on this program(the word search one), I've tried several approaches that don't work. Any more tips?
It sounds like you're fine with programming, but run into problems when working out the design of your applications. Take a step back from the coding for a bit, and write out with a pen and paper how you'd like your application to be designed. You should take into account of what your user sees, as well as how it would work in the backend. What classes will you need? How do the classes interact? Can you apply any patterns to your design?
Rob Loach [Website] [Projects] [Contact]
Quote:Original post by Rob Loach
It sounds like you're fine with programming, but run into problems when working out the design of your applications. Take a step back from the coding for a bit, and write out with a pen and paper how you'd like your application to be designed. You should take into account of what your user sees, as well as how it would work in the backend. What classes will you need? How do the classes interact? Can you apply any patterns to your design?


Your statement about deciding what classes I need reminded me of another issue I have. I almost never use classes when coding. I learned C as my first language, but quickly caught onto Python when I realized how much more effective it was for pretty much any application. However, OO design has never "clicked" with me, and I tend to write everything pretty procedurally based. This is another symptom of my larger problem of being unable to take on larger projects effectively. Should I make an active effort to learn OO design techniques? Any good books on the topic, or general software engineering?
Ok, I've made some progress. I am working on my Grid class, which will contain the actual puzzle itself. I have added methods to initilize the grid to a certain size, and methods to check if rows, columns, or diagonals are full, since I know this will be important later on. Now, do I want to place the logic for adding a word to the grid into the class itself, or do I want to have an outside function work with the class to add the word. To clarify, if I let the class handle all the logic, adding a word would look like this:
myGrid.addword(word)


Otherwise, I would have another set of logic on the outside using the methods in the class to determine the proper positioning of the word, and pass all those location parameters to the class instance to fill in the puzzle. I'm inclined to make the logic internalized, but it also occurs to me making a more generalized grid class would be more useful for reusing it later on (possible extending it for a board game like tic-tace-toe, checkers, or chess). Any thoughts or advice on the standard practice here?
Hey, if may I add something, don't oyu think you are taking a step that is too long? I mean, these things you are trying aren't as trivials as they seems to be... I'm not shure were to begin when making an Tic-Tac-Toe AI (you know what, I think I'm gona try to make one!).

But hey, maybe with more effort, you might actually make it, who knows... anyway, good luck with that.
Quote:Original post by algumacoisaqualquer
Hey, if may I add something, don't oyu think you are taking a step that is too long? I mean, these things you are trying aren't as trivials as they seems to be... I'm not shure were to begin when making an Tic-Tac-Toe AI (you know what, I think I'm gona try to make one!).

But hey, maybe with more effort, you might actually make it, who knows... anyway, good luck with that.
If you try to make one you'll need to figure out where to begin. And that would be by learning how to play Tic-Tac-Toe well. It doesn't take long to figure it out.

Convercely you could write a program that will learn how to play Tic-Tac-Toe. Something that will play randomly at first, but eliminate loosing combinations. If you can then figure out how to make the compute equate symetrical moves, the computer will be able to learn very quickly. (like how playing a peice in the top left corner on the second move is the same a playing any other corner.
You real question boils down to a design problem. How much functionality do you implement in your grid class vs. building an intermediate class that holds that functionality. If the idea of seperating the solution into multiple classes seems too foreign, I would implement all of the functionality in the grid class and then revisit it at a later time until the "light" bulb goes off.

From a design perspective you should build in a layer of abstraction from the UI and rules/logic.

A good book to get a better understanding on designs is "Design Patterns: Elements of Reusable Object-Oriented Software" ISBN := 0-201-63361-2
Ok, I'll check that out. I've decided to simplify things a bit and make a battleship game instead. I can wrap my ahead around what needs to be done for that much more easily, and should get me some good practice.

This topic is closed to new replies.

Advertisement