Class: Amaze::Grid::Upsilon

Inherits:
Amaze::Grid show all
Defined in:
lib/amaze/grid/upsilon.rb

Instance Attribute Summary

Attributes inherited from Amaze::Grid

#columns, #grid, #rows

Instance Method Summary collapse

Methods inherited from Amaze::Grid

#[], #deadends, #each_cell, #each_row, #initialize, #random_cell, #size

Constructor Details

This class inherits a constructor from Amaze::Grid

Instance Method Details

#configure_cellObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/amaze/grid/upsilon.rb', line 15

def configure_cell
  each_cell do |cell|
    row, column = cell.row, cell.column

    cell.north = self[row-1, column]
    cell.east = self[row, column+1]
    cell.south = self[row+1, column]
    cell.west = self[row, column-1]

    # Octo
    if (cell.row+cell.column).even?
      cell.northeast = self[row-1, column+1]
      cell.southeast = self[row+1, column+1]
      cell.southwest = self[row+1, column-1]
      cell.northwest = self[row-1, column-1]
    end
  end
end

#prepare_gridObject



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/amaze/grid/upsilon.rb', line 3

def prepare_grid
  @grid = Array.new(rows) do |row|
    Array.new(columns) do |column|
      if (row+column).even?
        Amaze::Cell::Octo.new row, column
      else
        Amaze::Cell::Square.new row, column
      end
    end
  end
end