Git Product home page Git Product logo

maze's Introduction

用Python生成迷宫的源代码

算法简介

  1. 生成一张网格,把网格里面的所有都存进一个列表edgeList里面.
  2. (0, 0)开始,做DFS。每次DFS的时候,随机地选择四周一个没有走过的格子,凿墙过去,把道路打通。凿墙的时候,把edgeList列表中相对应的那堵墙删除掉。
  3. 将剩下的没有凿开过的墙画出来,就是一个完整的迷宫了。

Generate a maze using Python

A Brief Description of the Algorithm

  1. Generate a grid of a given width and height. Save all the edges into list named edgeList.
  2. Starting from the cell (0, 0), perform a DFS search. In each step, randomly pick a unvisited neighbour cell, and break the wall in between. More specifically, when breaking the wall, what we need to do is just to remove the corresponding edge from the edgeList.
  3. Sketch all the rest edges in the edgeList and then we may get a maze.

Execution

The program depends on the matplotlib module. You need to install the module first to run the code.

pip install matplotlib

To execute the code, just simply type:

python maze.py

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.