performance - Most efficient way to decide if there are no moves left in a grid game? -


i have simple game can move game piece 1 square vertically or horizontally in grid make row of 3 pieces of same type.

the game grid 8 squares wide , 7 squares high, want find efficient way of checking if there no moves left result in 3 in row.

what have far :

grid checking plan

http://i.imgur.com/jy6wjvz.png

my thinking test horizontally need check column c isn't same piece type either side , same column f.

vertically - thought row 2 needs compared row 3 make sure nothing matches , column 5 should compared rows 4 , 6 matches.

so if none of match there can't possibly more moves?

i'm not sure if efficient way or if miss possible matches, can better brain mine please point me in right direction?

your check not guarantee there no moves. example, suppose top-left corner were:

      *     *   a b c . . . . * c c b . . . .   b b d . . . .   . . . . . . . . * . . . . . . . .   . . . . . . . .   . . . . . . . . 

indeed, no cell in column c equal either left or right of it, , no cell in row 2 equal either above or below it. yet, can swap c1 , c2 create 3-in-a-row.

as @patashu suggested, naive solution may best here, conceptualization, e.g. if else read code. track 3 cells @ time (in bounded fifo queue), first rows, columns, , when 2 of 3 match, check 2 6 surrounding cells can possibly swapped filling third. example,

  . . . . . . . .   . . * . . * . .   . * . a . * .   . . * . . * . .   . . . . . . . .   . . . . . . . .   . . . . . . . . 

or

  . . . . . . . .   . . . . * . . .   . . . . . .   . . . . * . . .   . . . . . . . .   . . . . . . . .   . . . . . . . . 

or

  . . . . . . . .   . . . . . . . .   . . . . . . . .   . . . . . . . .   . . . . . . . .   . . . . . * . .   . . . . * . a 

if of these *'ed cells match (e.g. a), know 3-in-a-row possible.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -