Class: Theseus::Algorithms::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/theseus/algorithms/base.rb

Overview

A minimal abstract superclass for maze algorithms to descend from, mostly as a helper to provide some basic, common functionality.

Direct Known Subclasses

Kruskal, Prim, RecursiveBacktracker

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(maze, options = {}) ⇒ Base

Create a new algorithm object that will operate on the given maze.



12
13
14
15
# File 'lib/theseus/algorithms/base.rb', line 12

def initialize(maze, options={})
  @maze = maze
  @pending = true
end

Instance Attribute Details

#mazeObject (readonly)

The maze object that the algorithm will operate on.



8
9
10
# File 'lib/theseus/algorithms/base.rb', line 8

def maze
  @maze
end

Instance Method Details

#pending?Boolean

Returns true if the algorithm has not yet completed.

Returns:

  • (Boolean)


18
19
20
# File 'lib/theseus/algorithms/base.rb', line 18

def pending?
  @pending
end

#stepObject

Execute a single step of the algorithm. Return true if the algorithm is still pending, or false if it has completed.



25
26
27
28
# File 'lib/theseus/algorithms/base.rb', line 25

def step
  return false unless pending?
  do_step
end