GithubHelp home page GithubHelp logo

cs-3345-project-3-mazes's Introduction

Mazes

This project was created for CS 3345 (Data Structures and Algorithms), and aims to be a demonstration of the disjoint sets data structure as well as Dijkstra's Algorithm.

Its core functionality is to generate a maze of a user-specified size, and then, when instructed, give a solution of that maze. The solution will be given in the form of a cardinal direction path (NESW) in terminal, along with being drawn.

Maze Generation

Maze generation is accomplished using disjoint sets, and is performed during construction of the Maze object. When a Maze is constructed, it will be populated with a randomly generated maze configuration. This configuration allows for only one entrance and exit, but ensures each and every cell within the maze is reachable from every other cell (a good maze uses all the area available to it).

Associated public-facing methods:

  • Maze(int n, int m)
    • Input: Two ints representing the horizontal and vertical size of the maze, respectively.
    • Output: a reference to a new Maze object with a randomly generated maze.

Maze Solving

Maze solving is also implemented within the maze class. It's performed using an implementation of Dijkstra's algorithm - each cell is considered a vertex, and has a cost associated with it (distance from start to that cell). The path is a sequence which doesn't skip any steps but also doesn't take any unnecessary ones.

Associated public-facing mehtods:

  • solve()

    • Input: Nothing
    • Output: a String with the path from start to finish written in cardinal direction instructions (i.e. "EESWSEE").
  • printMaze

    • Detailed below

Maze Printing

  • printMaze(boolean solutionMode)
    • Input: A boolean representing whether or not to show the solution path. If true, outputs an @ for each cell in the solution path.
    • Output: Prints an ASCII representation of the maze to screen.
      • ], - and ] represent walls.
      • @ represents a solution.
      • are navigable spaces.

Disjoint Set Implementation

This was just a super straightforward implmentation. It was done only with ints, no generics, and employs union by rank and path compression.

Sample

Enter the number of rows, n (0 to exit):
> 10
Enter the number of columns, m (0 to exit):
> 10
Maze is done generating!
  []-[]-[]-[]-[]-[]-[]-[]-[]-[
     [] [] []             [] [
]-[] [] [] [] []-[] [] [] [] [
]                [] [] []    [
]-[]-[]-[] [] []-[] []-[]-[] [
]       [] [] []    [] []    [
]-[] []-[]-[] []-[] [] []-[] [
]       []       []       [] [
]-[] [] [] [] [] [] [] []-[]-[
]    []    [] [] [] [] []    [
]-[]-[]-[] []-[]-[]-[]-[] []-[
] []       []    [] [] []    [
] [] []-[] []-[] [] [] []-[] [
] [] []                      [
] []-[] []-[]-[]-[]-[]-[] [] [
]    []       [] []       [] [
]-[] [] []-[] [] [] [] []-[] [
]          [] []    [] [] [] [
] [] [] [] []-[] [] []-[] []-[
] [] [] [] []    []
]-[]-[]-[]-[]-[]-[]-[]-[]-[]

Press Enter to see the solution.

Here's how you'd solve it (Follow the '@'s).
  []-[]-[]-[]-[]-[]-[]-[]-[]-[
 @  @[] [] []             [] [
]-[] [] [] [] []-[] [] [] [] [
]   @  @  @  @   [] [] []    [
]-[]-[]-[] [] []-[] []-[]-[] [
]       [] []@[]    [] []    [
]-[] []-[]-[] []-[] [] []-[] [
]       []@  @   []       [] [
]-[] [] [] [] [] [] [] []-[]-[
]    []   @[] [] [] [] []    [
]-[]-[]-[] []-[]-[]-[]-[] []-[
] []      @[]    [] [] []    [
] [] []-[] []-[] [] [] []-[] [
] [] []   @  @  @  @  @  @   [
] []-[] []-[]-[]-[]-[]-[] [] [
]    []       [] []@  @  @[] [
]-[] [] []-[] [] [] [] []-[] [
]          [] []   @[] [] [] [
] [] [] [] []-[] [] []-[] []-[
] [] [] [] []    []@  @  @  @
]-[]-[]-[]-[]-[]-[]-[]-[]-[]

Your solution string was :
ESEEESSWSSSEEEEESWWSSEEE

cs-3345-project-3-mazes's People

Contributors

cameron-b63 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.