Giter VIP home page Giter VIP logo

maze's Introduction

Maze

Generates a maze using Randomised Kruskal's Algorithm. Displays maze with JavaFX, and allows the user to interact with it.

Has 2 classes, Maze and Test.

Main runs the game.

Maze.java

Class that generates maze.

Methods

Constructor

Maze maze = new Maze(n, m);

Where it generates a Maze object of dimensions n by m.

n by m is the same as x by y.

getWallPosition()

List<Integer> list = maze.getWallPosition();

Returns a List of integers representing walls.

For a 3 by 3 maze,

Walls of maze

getSquares()

Returns a

HashMap<Integer, List<Integer>>

Where the key is the square number (starting from 1) and the value is a list of integers representing the walls surrounding it.

For the same 3 by 3 grid,

maze.getSquares();

returns:

{
    1: [1, 7],
    2: [1, 2, 8],
    3: [2, 9],
    4: [3, 10],
    5: [3, 4, 11],
    6: [4, 12],
    7: [5, 10],
    8: [5, 6, 11],
    9: [6, 12]
}

Removing a wall and merging 2 squares just merges 2 list together and removes the common number. (e.g. [1, 7] and [1, 2, 8] becomes [2, 7, 8] when square 1 and 2 are merged)

Randomised kruskal's algorithm

Randomised Kruskal's Algorithm works by removing the walls of the maze and merging each cell until there is only 1 cell remaining.

For example, take the 3 by 3 grid above. Say we remove wall 8, squares 2 and 5 are now merged to form a cell: Walls of maze

Now, we remove wall 3 and merge square 4 with the previously merged cell:

Walls of maze

Then, we remove wall 11 and merge square 8 with the cell:

Walls of maze

We remove wall 10 and merge square 7 with the cell:

Walls of maze

Now we select to remove wall 5. However we cannot do this because square 7 and 8 are already merged to a single cell.

Walls of maze

Repeat until all the squares are merged into one cell.

Test.java

Testing class to test speed of program.

Method

test

public static void test(int n, int m)

Outputs the time taken for the maze to generate.

(100 by 100 maze takes around 2.5 seconds)

Main.java

Sample screenshots of a 20 by 20 maze

Maze with path

Maze with previous route shown.

Maze without previous path

Maze with previous route hidden.

Maze solved

Maze solved

maze's People

Contributors

ajlee2006 avatar josherlo avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

maze's Issues

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.