int blocks [width, height] flexible[] coord stack clickblock (x, y) { stack.push_back(x, y)//thefirst block col = blocks[x,y] while (!done) { done = checkblock(coords.end().x, coords.end().y, col) } } bool checkblock(x, y, col) { blocks[x, y] = 0 for (each block bl around x/y in blocks) { if (bl == col) { stack.pushback(x of bl, y of bl)//reset the return 0//it's not done } } stack.popback()//remove the last of the stack, continue checking the block below return stack.size() }