Class: MazeCrosser::Maze
- Inherits:
-
Object
- Object
- MazeCrosser::Maze
- Includes:
- BasicGridValidator
- Defined in:
- lib/maze_crosser/maze.rb
Overview
Class responsible for representing a maze.
maze = Maze.new(grid)
Check if the coordinates are inside the grid maze.inside_grid? [4, 2]
Check if a cell is blocked maze.blocked_cell? [4, 2]
Constant Summary
Constants included from BasicGridValidator
BasicGridValidator::ALLOWED_CHARACTERS
Instance Attribute Summary collapse
-
#goal ⇒ Object
readonly
Returns the value of attribute goal.
-
#grid ⇒ Object
readonly
Returns the value of attribute grid.
-
#number_of_columns ⇒ Object
readonly
Returns the value of attribute number_of_columns.
-
#number_of_rows ⇒ Object
readonly
Returns the value of attribute number_of_rows.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Instance Method Summary collapse
- #blocked_cell?(coordinates) ⇒ Boolean
-
#initialize(grid) ⇒ Maze
constructor
A new instance of Maze.
- #inside_grid?(coordinates) ⇒ Boolean
Methods included from BasicGridValidator
Constructor Details
#initialize(grid) ⇒ Maze
Returns a new instance of Maze.
22 23 24 25 26 27 28 29 |
# File 'lib/maze_crosser/maze.rb', line 22 def initialize(grid) raise ArgumentError, 'Invalid maze' unless valid? grid @grid = grid set_dimensions set_start set_goal end |
Instance Attribute Details
#goal ⇒ Object (readonly)
Returns the value of attribute goal.
16 17 18 |
# File 'lib/maze_crosser/maze.rb', line 16 def goal @goal end |
#grid ⇒ Object (readonly)
Returns the value of attribute grid.
16 17 18 |
# File 'lib/maze_crosser/maze.rb', line 16 def grid @grid end |
#number_of_columns ⇒ Object (readonly)
Returns the value of attribute number_of_columns.
16 17 18 |
# File 'lib/maze_crosser/maze.rb', line 16 def number_of_columns @number_of_columns end |
#number_of_rows ⇒ Object (readonly)
Returns the value of attribute number_of_rows.
16 17 18 |
# File 'lib/maze_crosser/maze.rb', line 16 def number_of_rows @number_of_rows end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
16 17 18 |
# File 'lib/maze_crosser/maze.rb', line 16 def start @start end |
Instance Method Details
#blocked_cell?(coordinates) ⇒ Boolean
36 37 38 |
# File 'lib/maze_crosser/maze.rb', line 36 def blocked_cell?(coordinates) @grid[coordinates[0]][coordinates[1]] == ALLOWED_CHARACTERS[:blocked] end |
#inside_grid?(coordinates) ⇒ Boolean
31 32 33 34 |
# File 'lib/maze_crosser/maze.rb', line 31 def inside_grid?(coordinates) coordinates[0].between?(0, @number_of_rows - 1) && \ coordinates[1].between?(0, @number_of_columns - 1) end |