tags:

views:

152

answers:

1

Hello, Im making a game that involves a 4*4 grid the user enters letters and the game has to highlight the letters and they have to be next to one another.

I have a sub that checks if the current letter is next to (or neighbouring) the last letter. Basically what needs to happen is :

for each letter iterate through the grid and try every possibility if it is next to the previous letter, and the current letter matches the target letter

then it tries every possibility for each leter so it needs to iterate 16 ^ (number of letters)

if someone could lead me in the right direction, or give me a better algorithm id really appreciate it. I'm using vb .net but psuedocode works too.

Thanks

A: 

If I get this right the grid could look like:

A B C D

B A D C

C C A B

D B C A

Then the user should type A B C D B A and so on to win?

One thing to consider is that if you remember all the positions where the first keystroke matched, lets say the user pressed A, then index 0,5,10,15 would be marked.

The next keypress is only valid if the previous key press was next to the current so insted of checking every item in the grid check 0+1, 5+1, 10+1 and 15+1 for the key press.

So if the user presses D, then you would see that index 1 is not a D index 6 is acutally a D so lets mark it, and so on.

Daniel Persson