Git Product home page Git Product logo

flood-fill's Introduction

Flood-fill

An algorithm to solve maze

Problem statement:

A maze image,start cell coordinate and end cell coordinate will be provided. We have to find the path. Note that maze is given as an image.(So, image preprocessing stuff is involved here!!). Maze to be considered as 10*10 cells.

Given maze:


Solution:


First, lets interpret the maze image. Given is a 3 channel image, walls and boundries are black and free spaces are white. Since the image is a 3d matrix of numbers lets normalize it to 1d matrix for easy processing.

Image normalization:
Image is converted into single channel, where walls hold 0s and free spaces as 1

Flood fill
Flood the matrix The algorithm proceed in the following way,
1.Initialize marker variable value to 0
2.Fill marker value to end cell and increment marker value
3.Fill adjacent cell without wall inbetween with marker value
4.Increment marker value
5.Repeat step 3 and 4 till every cell in the matrix is filled.

Once I filled the above maze it look like this,


Tracing the path
Once, The matrix is filled the path can be traced by starting from the intial cell and moving to adjacent cell(Without wall inbetween) which has smallest value.
So, for above maze

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.