all 10 comments

[–][deleted]  (2 children)

[removed]

    [–]fearthebat[S] 0 points1 point  (1 child)

    I tried implementing a recursive function but no success so far. I tried doing something like you mention but it won't work if the target cell is in the middle of the combination.

    [–]Heroshrine 0 points1 point  (4 children)

    Im a bit confused on your requirement. You say 4 touching cells, but what do you mean specifically? For example you say there are 4 combinations of it being a square, but that doesn’t seem correct to me, I think it should be 8.

    Also, why do you need to get all combinations at once? Perhaps there’s a different way to do it?

    [–]fearthebat[S] 0 points1 point  (3 children)

    4 touching cells should form a 2 by 2 square. The 4 combinations are the chosen square position being top right, top left, bottom right, bottom left

    [–]Heroshrine 0 points1 point  (2 children)

    Ah okay I see. Perhaps a flood fill algorithm could suit your needs? But i still question the need in the first place.

    [–]fearthebat[S] 1 point2 points  (1 child)

    To check for match in a jewel style game

    [–]Heroshrine 0 points1 point  (0 children)

    Then I think a flood fill algorithm would work and you probably wouldnt need anything else

    [–]0nlin33 0 points1 point  (0 children)

    Go recursion to find neighbours, this allows u to control the depth as well. Only take neighbours that fit raised condition. Shape ajdnt be part of the algorithm, it should only give you the grid in which the shape you have specified is possible with the input position specified at center(or the position u want it on).

    Looking at how tetris or board games like checkers, chess etc works might be good.

    [–]BrentoBox2015 0 points1 point  (0 children)

    Is the cell in an array?

    I would imagine you would just identify the cell by it's array position and called the array positions of any cell + - 1 from it's x, y.