No commit activity in last 3 years
No release in over 3 years
This gem allows to find path to cheese in a labyrinth
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

subparry_labyrinth_solver

codecov Build Status Gem Version

Description

Fun little project about labyrinth solving inspired in mice that find cheese in a maze.

It exposes some classes to create a labyrinth and then find the path to the cheese.

Note that although the paths found are mostly efficient, the algorithm does not focus on finding the best path to the cheese.

Usage

gem install subparry_labyrinth_solver
require 'subparry_labyrinth_solver'

# First define labyrinth data as a 2 dimensional array where
# each square is represented by a hash with :up, :down, :left and :right
# as keys and an optional key :cheese representing the "goal" square.
# A value of true for a direction represents an open path, and false
# represents a wall.

data = [
  [ # The first row
    { up: false, right: false, left: false, down: true },
    { up: false, right: false, left: false, down: true, cheese: true },
  ],
  [ # The second row
    { up: true, down: false, right: true, left: false },
    { up: true, down: false, right: false, left: true }
  ]
]

# The above data represents this maze:
#      ___ ___
#     |   | 🧀|
#     |   |   |
#     |       |
#     |_______|

# Then initialize the labyrinth:
lab = LabyrinthSolver::Labyrinth.new(data)

# Then initialize the solver:
solver = LabyrinthSolver::Solver.new(lab)

# And call solve on the instance. This call will trigger
# the cheese-finding loop and record the right path.
solver.solve

# Confirm that cheese was found:
solver.cheese? # => true

# Retrieve the path:
solver.path # => [:down, :right, :up]

# Get the coordinates of the cheese:
solver.position # => <struct x: 1, y: 0>

# Note that the coordinates are like image coordinates where top-left
# corner is x: 0, y: 0 and bottom-right is x: width, y: length

Pending

  • Create a labyrinth maker class
  • Visual representation of labyrinths
  • Document Node and Labyrinth classes