Floodfill algorithm for GO

Posted by user1048606 on Game Development See other posts from Game Development or by user1048606
Published on 2012-04-02T21:21:42Z Indexed on 2012/04/03 5:41 UTC
Read the original article Hit count: 309

Filed under:

The floodfill algorithm is used in the bucket tool in MS paint and photoshop, but it can also be used for GO and minesweeper.

http://en.wikipedia.org/wiki/Flood_fill

In go you can capture groups of stones, this website portrays it with two stones. http://www.connectedglobe.com/mindy/cap6.html

This is my floodfill method in Java, it is not capturing a group of stones and I have no idea why because to me it makes sense.

public void floodfill(int turn, int col, int row){
    for(int a = col; a<19; a++){
        for(int b = row; b<19; b++){
            if(turn == black){
                if(stones[col][row] == white){
                    stones[col][row] = 0;
                    floodfill(black, col-1, row);
                    floodfill(black, col+1, row);
                    floodfill(black, col, row-1);
                    floodfill(black, col, row+1);
                }
            }
        }
    }
}

It searches up, down, left, right for all the stones on the board. If the stones are white it captures them by making them 0, which represents empty.

© Game Development or respective owner

Related posts about java