0

Short question, I implemented the Flood Fill Algorithm (Basically the first pseudo-code) into my C++ code and it works perfectly only I need to record how many tiles it's removed from the origin like this person accomplished.

I'm not looking for manhattan distance though.

This is my code. I omitted unnecessary code.

class MovementTile
{
public:
    int x, y;
    bool CanMoveTo;
    bool IsPassable;
    bool Visited;

    MovementTile(int _x, int _y, bool _IsPassable)
    {
        x = _x;
        y = _y;
        IsPassable = _IsPassable;
        Visited = false;
        CanMoveTo = false;
    }

};

void Fill(MovementTile* _tile, int _x, int _y)
    {
        if (!_tile->Visited)
        {
            if (!_tile->IsPassable)
            {
                _tile->Visited = true;
            }
            else
            {
                _tile->Visited = true;
                _tile->CanMoveTo = true;

                if (_x - 1 > 0)
                {
                    Fill(TileList[_y][_x - 1], _x - 1, _y);
                }

                if (_y - 1 > 0)
                {
                    Fill(TileList[_y - 1][_x], _x, _y - 1);
                }

                if (_y + 1 < TileList[_y].size())
                {
                    Fill(TileList[_y + 1][_x], _x, _y + 1);
                }

                if (_x + 1 < TileList[_y].size())
                {
                    Fill(TileList[_y][_x + 1], _x + 1, _y);
                }
            }
        }
    }
Community
  • 1
  • 1
RayShawnOfNapalm
  • 210
  • 6
  • 20
  • 2
    Your code should be in the question itself. To format code, (1) paste it (2) select it (3) click the code button. The code button is in the tool bar above [edit] window and looks like this `{}` – user3386109 Aug 01 '16 at 20:54
  • This looks like 2D Grid map A* problem see [Backtracking in A star](http://stackoverflow.com/a/28317199/2521214) and the linked QA in my answer for C++ code. If you want to use your flood fill instead add the distance to recursion tail and increment it each recursion layer (but that will increase heap/stack usage) – Spektre Aug 03 '16 at 06:43

0 Answers0