Class: Amaze::Grid
- Inherits:
-
Object
show all
- Defined in:
- lib/amaze/grid.rb
Defined Under Namespace
Classes: Delta, Ortho, Polar, Sigma, Upsilon
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(rows, columns) ⇒ Grid
Returns a new instance of Grid.
15
16
17
18
19
20
21
|
# File 'lib/amaze/grid.rb', line 15
def initialize rows, columns
@rows = rows
@columns = columns
prepare_grid
configure_cell
end
|
Instance Attribute Details
#columns ⇒ Object
The dimension of the amaze
10
11
12
|
# File 'lib/amaze/grid.rb', line 10
def columns
@columns
end
|
#grid ⇒ Object
13
14
15
|
# File 'lib/amaze/grid.rb', line 13
def grid
@grid
end
|
#rows ⇒ Object
The dimension of the amaze
10
11
12
|
# File 'lib/amaze/grid.rb', line 10
def rows
@rows
end
|
Instance Method Details
#[](row, column) ⇒ Object
31
32
33
34
35
|
# File 'lib/amaze/grid.rb', line 31
def [](row, column)
return nil unless row.between?(0, rows-1)
return nil unless column.between?(0, columns-1)
grid[row][column]
end
|
27
28
29
|
# File 'lib/amaze/grid.rb', line 27
def configure_cell
raise NotImplementedError
end
|
#deadends ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/amaze/grid.rb', line 55
def deadends
list = []
each_cell do |cell|
list << cell if cell.links.size == 1
end
list
end
|
#each_cell ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/amaze/grid.rb', line 43
def each_cell
each_row do |row|
row.each do |cell|
yield cell if cell
end
end
end
|
#each_row ⇒ Object
37
38
39
40
41
|
# File 'lib/amaze/grid.rb', line 37
def each_row
grid.each do |row|
yield row
end
end
|
#prepare_grid ⇒ Object
23
24
25
|
# File 'lib/amaze/grid.rb', line 23
def prepare_grid
raise NotImplementedError
end
|
#random_cell ⇒ Object
51
52
53
|
# File 'lib/amaze/grid.rb', line 51
def random_cell
self[rand(rows), rand(columns)]
end
|
#size ⇒ Object
63
64
65
|
# File 'lib/amaze/grid.rb', line 63
def size
rows * columns
end
|