Skip to content

Latest commit

 

History

History
75 lines (55 loc) · 2.3 KB

README.md

File metadata and controls

75 lines (55 loc) · 2.3 KB

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