Can't you just iterate through an array and at each element, check for similar colors in each direction?
Actual playing board:
X X X Y X X
X X X Y X
X Z X X Y X
Z Z X X X [/CODE]could be compressed into an array aligned to the left (zero = invalid space):[code]
XXXYXX
XXXYX0
XZXXYX
ZZXXX0 Then just write code that looks at each element around the current one being checked (you will only ever be checking for elements touching the last one added). Make sure that your code adjusts for short lines versus long lines. Meaning that if you are looking at the two adjoining spaces above, tehn you must check array elements that are one greater and the same (or one less and the same).
Or perhaps it would be easier to just create a full array that stores all of the empty (can never contain a 'ball') spaces in between. Actual playing board:
X-X-X-Y-X-X
-X-X-X-Y-X-
X-Z-X-X-Y-X
-Z-Z-X-X-X-[/CODE]could be stored as an array where zeros = invalid spaces:[code]
X0X0X0Y0X0X
0X0X0X0Y0X0
X0Z0X0X0Y0X
0Z0Z0X0X0X0 And then always check 1 over in any direction from the current position. This might actually be easier.
I won't write any code, because by the time I did that, I could just as well make the game myself then :)
|