### Flood Fill Logic Question

Hi there,
I am writing an agent that will play a game of Tron. This was one of the Google AI challenges.
I have been trying to use a Flood Fill to calculate the area I have to move my sprite. combined with the minimax algorithm I should be able to look out for areas that block my agent in.

However my flood fill always appears to be returning zero and I cant work out why. It's 5am here so I think it might be my logic, can someone check it for me? I'd love to see this thing running before I go to sleep.

 ``1234567891011121314`` ``````int Board::FloodFill(int playerX, int playerY, vector>board) { int area = 0; if(!isFree(playerX, playerY)) return area; board[playerY][playerX] = WALL; area++; area += FloodFill(playerX - 1, playerY, board); //west area += FloodFill(playerX + 1, playerY, board); //east area += FloodFill(playerX, playerY - 1, board); //north area += FloodFill(playerX, playerY + 1, board); //south return area; }``````

 ``1234`` ``````bool isFree(int x, int y) { return board[y][x] == EMPTY; }``````
Because you are passing `board' by value, the modifications are local to the function.
That means that `north' is not aware of all the cells that were visited by `west'.

In order to revert to original, either made a wrapper or `paint' with another colour.

> my flood fill always appears to be returning zero
Make a step-by-step run trough a debugger.
Probably the function is always stopping at `isFree()' because your starting cell has the player.
Topic archived. No new replies allowed.