jeudi 4 février 2016

Word Puzzle - How to fix it going out of path?

I'm hoping someone can point me in the right direction with this issue.

For my project in school, we need to make a "Word Puzzle" solver. So there is a .txt file with a "grid" of letters, along with actual words under this grid that the puzzle needs to look for and see if they exist in the puzzle.

example:
4 4
s e l f
w t r g
a o o v
g x q e
frog
swag
self

The 4 4 represents the puzzle will be 4 letters wide, and 4 letters high.

The problem I am running into is that if, for example, we are searching for "frog". My program finds the 'f', then moves on to the next character in the word 'r'. It finds the 'r', then moves onto the 'o'. This is where my problem is. The way my program is designed uses a bunch of if else statements to check if the letter above, below, left, right, upright, downright, upleft, or downleft of the current location contains the next letter we are looking for.

So what happens is that it will pick the wrong 'o', and then try to find the 'g' after moving to 'o's location, but it can't because it took the wrong path.

My question is this: does anyone have an idea on how to fix this issue? I don't want a direct coding answer if possible, since this is an academic assignment and I don't want to cheat, but if someone could lead me in the right direction, I would be ecstatic!

Thank you.

Aucun commentaire:

Enregistrer un commentaire