Giter VIP home page Giter VIP logo

maze_builder's Introduction

maze_builder

A maze builder algorithm made in python. It was made inspired on this stackoverflow post.

The main logic is in the dig method in the class Maze. Once provided with a list of frontiers to explore, the algorithm will dig a maze, walking 2 steps into a random valid direction.

Assumptions:

  • A frontier is a cell chosen to explore for its neighbours, digging from it until there are no move moves available.
  • The algorithm does not intersect an existing tunnel. It shall continue digging avoiding passage areas.

It works as follows:

1 - Pick a random cell from frontiers list to explore (call it current_cell)

2 - Check current_cell's valid neighbors. This way, two situations can happen:

Case A : current_cell do not have a valid neighbor

3 - remove current_cell it from frontiers list.

4 - Repeat from 1 until there are no more cells in frontiers to explore.

Case B : current_cell has valid neighbors

3 - current_cell has valid neighbors, so random pick one and call it new_cell.

4 - Mark the new_cell (which is 2 steps away from current cell)

5 - Mark the cell between current_cell and new_cell, creating a passage.

6 - Add new_cell to frontiers list (so it shall be explored again in the future). Repeat from 1 until there are no more frontiers to explore.

Notes

  • The algorithm logic avoids creating open rooms.
  • Cells are marked as a passage before adding them to frontiers list.
  • So each time a new frontier is selected to explore the maze, there is no need to paint it again.
  • This assures that when looking for a new neighbor, the rejected neighbor cells does not reappears in the frontiers list.
  • It is a simple way to avoid adding the same cell to the frontiers list multiple times.
  • It also avoids adding cells that are already part of the maze.

maze_builder's People

Contributors

toaster-code avatar

Watchers

 avatar

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.