Floodfill Algorithm Overview: Maze Representation and Update Distances

Floodfill Algorithm Overview: Maze Representation and Update Distances
Slide Note
Embed
Share

"Learn about floodfill algorithm principles, maze representation, and update distances. Understand the process of assigning distances to cells and updating them. Get insights on optimizing the algorithm, debugging with print maze function, and essential tips for efficient implementation."

  • Algorithm
  • Maze
  • Floodfill
  • Update
  • Optimization

Uploaded on Mar 17, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Lecture 4: Floodfill

  2. Floodfill Overview First assume that there are no walls Give each cell a distance from the goal. The goal has distance 0. Repeat until we reach the goal: Go to the neighboring cell with the smallest distance to the goal Run the update distances algorithm (see later slide)

  3. Example

  4. Maze Representation Each cell has a distance (0-252 for a 16 x 16 maze) and 4 walls (1 bit each). You may also want to have a visited bit for speed runs. When you discover a wall, you need to update it in the current cell, and the neighboring cell. You can get around this by giving each cell only 2 walls, but you need an extra dummy row/col. If you use the visited bit, then you don t need to run the floodfill update algorithm on cells that you have already visited, meaning you can go faster on them.

  5. Print maze function It is essential for debugging to be able to print out your maze Should look something like this: +---+---+---+ |*5 *4 V3 | +---+---+ + | 0 1 2 | +---+---+---+ Use + for posts. Use --- for north/south walls. Use | (pipe) for east/west walls. Use * for visited. Use <, >, ^, V for the direction of the mouse.

  6. Update distances algorithm (no recursion) Make sure the stack is empty If there are any new walls discovered: Push the current cell and the cells adjacent to the new walls onto the stack While the stack is not empty: currCell <- pop the top of the stack The distance of currCell should be the minimum open neighbor distance + 1 If it is not, then set it to that value and push all open neighbors to the stack

  7. Tips Run your floodfill algorithm as soon as your mouse enters the cell, not when it reaches the center of the cell. Write a simulator in Visual Studio to test your function. Also use Green s maze generation excel sheet to create test mazes. The stack for the update distances algorithm should be 512. (Note that it is possible to add a cell more than once, therefore 255 may not be enough). Place your stack outside of any function (make it global). You might run out of memory if you place large arrays inside of functions. Global variables go into a different region of memory, where there is more space. Don t use recursion. You usually want to avoid using recursion on embedded systems, since it is slow and wastes more memory than a stack-based method.

More Related Content