class TowersOfHanoi::Board::Tower

Public Class Methods

new(max_bricks: 3, bricks: 0) click to toggle source
# File lib/towers_of_hanoi/board/tower.rb, line 4
def initialize(max_bricks: 3, bricks: 0)
  @max_bricks = max_bricks
  @bricks = Array.new(bricks).map.with_index do |el, idx|
    TowersOfHanoi::Board::Brick.new(width: max_bricks - idx)
  end
end

Public Instance Methods

add(new_brick) click to toggle source
# File lib/towers_of_hanoi/board/tower.rb, line 29
def add(new_brick)
  @bricks.push(new_brick)
end
brick(position) click to toggle source
# File lib/towers_of_hanoi/board/tower.rb, line 23
def brick(position)
  if (1..@max_bricks) === position
    @bricks[position - 1] || TowersOfHanoi::Board::Brick.new
  end
end
full?() click to toggle source
# File lib/towers_of_hanoi/board/tower.rb, line 19
def full?
  height == @max_bricks
end
height() click to toggle source
# File lib/towers_of_hanoi/board/tower.rb, line 11
def height
  @bricks.length
end
remove() click to toggle source
# File lib/towers_of_hanoi/board/tower.rb, line 33
def remove
  @bricks.pop
end
top() click to toggle source
# File lib/towers_of_hanoi/board/tower.rb, line 15
def top
  brick(height) || TowersOfHanoi::Board::Base.new(width: @max_bricks + 1)
end