Giter Site home page Giter Site logo

maze_magic's Introduction

Build Status Code Climate Test Coverage

MazeMagic

Ruby Maze generating gem.

 _______________________________________________________________________________________________________________________ 
| | |  _________     _____  |___  |  _  |    _____  |  ___  |___   ___  |  _  |  ___  |   |___   _|    ___________  |   |
| | | |  _  |   |_| |_    |___  |  _|  _| | |  ___| | |   |_  |  _| |  _| |_  |_  | | | |___  |_____|  _  |  _  | | |_| |
| |_____|_  | |_  |   |_|___  | |_|   |  _| |  _____|  _| |_____| |  _| |   |  ___|_____|  ___|  _  | | |___| | | |_  | |
|_______  |_| |  _| | |  _  | | |  _|_| |  _|_  |___  |   |  _  | | |   | | |_|  ___  | |___  | | | |___  |   | | |  _| |
|_  |  ___|  _| |___| | | | | | | |  ___| |  _|___  | | |_|_  | | | | |___|_   _____| |  _____| | |_  | | |_| | | |___  |
|   | |  _  |_________| |___  | |  _____| |   |  ___| |_______| | | |___|   |_  |  ___|_  |  _  | |  _|_______| |    _| |
| | | |_  |_  | |    _|  _  |_| |___|  ___| | | |  ___|_  |  ___| |_______|_  |_| | |  ___|___| |  _|  _________| |_____|
| | |_  |___| |___| |  ___|_  |_______|  _| |___|___   ___| |   |   |  _______|  _| |_  |  _____|_  | | |    ___| | |   |
| |___| |   | |  ___| | |  _______|  _  |  _|   |   |_|  ___| | | | |_  |_    |_  |  _| |_  | |   |___|  _| |  ___|___| |
|_________|___|_________|_____________|_______|___|_____|_____|___|_________|_____|_________|___|_________|_____________|

Installation

Add this line to your application's Gemfile:

gem 'maze_magic'

And then execute:

$ bundle

Usage

Simple use:

require 'maze_magic'

# maze is a 2 dimensional array of these singleton objects:
#
#       MazeMagic::Edge.instance              # ' '
#       MazeMagic::HorizontalWall.instance    #  _
#       MazeMagic::VerticalWall.instance      #  |
#       MazeMagic::Passage.instance           # ' '
#
# so something like:
#
#    [[Edge, HW, HW, HW, HW, Edge],[VW, P, P,VW,P,P,P, HW],...]
#
def generate_maze(height: 5, width: 5)
  MazeMagic::Generate
    .new(height: height, width: width)
    .tap { |g| g.generate_maze }
    .maze
end

maze = generate_maze

# optional: render in console
MazeMagic::Renderer::ConsoleRenderer.new(cells_grid: maze).call

#  _________ 
# |_  |  _  |
# |  _| |  _|
# | |_  | | |
# | |  _| | |
# |___|_____|

More Complex use:

MazeMagic::Generate is just an Interface. For more complex usage check lib/maze_magic/generate.rb, ...or specs.

Usage in web-app

You can check https://github.com/equivalent/a-maze-ing for example Rails application, but the point is that you will represent the "Maze Wall Representation Objects" as walls/passages. (e.g. <div class="horizontal-wall"></div>, ...; or <img src="/public/horizontal-wall.png">)

stupid example:

@maze = generate_maze(height: 5, width: 5)
<div id="maze">
  <% @maze.each_with_index do |row, index| %>
    <div class="maze-row maze-row-<%= index %>">
      <% row.each do |maze_rep| %>
        <% if maze_rep.is_a? MazeMagic::HorizontalWall  %>
           <img src="/public/horizontal-wall.png">
        <% elsif maze_rep.is_a? MazeMagic::Passage %>
           <img src="/public/passage.png">
           # ...
        <% end %>
      <% end %>
    </div>
    <div class=clear-fix></div>
  <% end %>
</div>

Maze generating Algorithm

At this point there is just altered version of Recursive Backtracking algorithm, but the the gem can be extended by any algorithm.

Contributing

Bug reports and pull requests are welcome. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

TODO

maze_magic's People

Contributors

equivalent avatar

Stargazers

Marcos Junior avatar Vinh Quốc Nguyễn avatar Michael Chrisco avatar Robin Stammer avatar Marco avatar Conor Wright avatar Manoj avatar Abhinay Kumar avatar Adrian O'Connor avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

rafehatfield

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.