Floodfill algorithm for GO
- by user1048606
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.