Coder Social home page Coder Social logo

maze-generator's Introduction

Maze-Generator

Run Maze-generator!.py

The following project is capable of generating unique mazes of varying difficulties. The user can attempt to solve the mazes on the screen using arrow keys. The program is also capable of saving these mazes as csv files so that the mazes can be attempted later or by a different user. The user interface provides a game-like experience where different users can create separate accounts and attempt the same mazes. Users can view their time taken to solve the maze and their best time at a maze of that difficulty.

Sample maze

image

Maze Algorithm

In order to draw the maze, we have used several pygame features. The maze consists of a grid of coordinates - a 2D list in our program. After drawing the borders and openings of the maze, the remaining coordinates are filled using randomly generated snake lines.

Snake lines:

The program creates a list of directions which represent a line that would look natural in a maze and will not form closed loops or spirals. These randomly generated lines usually resemble snakes, hence we are calling them snake lines. A random coordinate in the maze is chosen as the start point of the snake line. The general direction of the line is chosen. A snake line moving in that direction is created. The snake line is drawn until it reaches a coordinate which is already filled.

image

This ensures that the mazes generated by this algorithm will always have a proper solution and there will only be one solution for each maze.

Saving a maze as a CSV:

The program also converts a maze into a csv using the pygame function window.get_at to check the colour of the point in between two coordinates, i.e. whether there is a line between all adjacent pairs of coordinates. The CSV file stores these values for each coordinate in the maze as 00, 01, 10 or 11. Where 00 represents that there is no line connecting it to the coordinate to the right or below and 01 represents that there is no line between that coordinate and the coordinate on the right but there is a line between that coordinate and the one below.

Given below is a sample maze and its corresponding save values. image

Recreating mazes from csv

The program can read the csv files to recreate mazes. The mazes are saved as username_maze(date and time of creating the maze). The program uses the module datetime for this task. If the user chooses to rename the csv files, it will not affect the program. While recreating mazes, the user can select the maze files from their device.

User and interface features

The user interface was created using a combination of tkinter and pygame. Users can create an account with a username and password to keep track of the mazes they attempt and improve their highscore. The user data (password and highscores) is stored in a binary file. After logging in to their account, the user can choose to generate a new maze or attempt a previously saved maze. If the player chooses to generate a new maze, they can select the difficulty of the maze to be generated. Our project creates mazes of 4 different levels of difficulty. Larger mazes are more difficult to solve, therefore, the largest mazes are level 4 and the smallest mazes are level 1.

Solving the maze:

The user can draw a path across the maze using arrow keys. To retrace their path, the user can use backspace. However, if the user attempts to draw a line over a wall, it will result in a loss. Then the user is given the choice to try again or give up. On successfully completing a maze, the user is shown the time they have taken to solve the maze as well as their best time on a maze of that difficulty. Then, the user is given the option to save that maze.

License

CC0-1.0 license

maze-generator's People

Contributors

sh-r-eya 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.