class TowersOfHanoi::Game
Attributes
board[R]
Public Class Methods
new(bricks: 3, moves: [])
click to toggle source
# File lib/towers_of_hanoi/game.rb, line 5 def initialize(bricks: 3, moves: []) @board = TowersOfHanoi::Board.new(bricks: bricks) @moves = [] moves.each { |turn| move(from: turn[0], to: turn[1]) } end
Public Instance Methods
minimum_turns()
click to toggle source
# File lib/towers_of_hanoi/game.rb, line 28 def minimum_turns 2**number_of_bricks - 1 end
move(from: 0, to: 0)
click to toggle source
# File lib/towers_of_hanoi/game.rb, line 23 def move(from: 0, to: 0) new_move = TowersOfHanoi::Move.new(origin: from, destination: to) @moves << new_move.make(@board) end
number_of_bricks()
click to toggle source
# File lib/towers_of_hanoi/game.rb, line 11 def number_of_bricks @board.bricks end
over?()
click to toggle source
# File lib/towers_of_hanoi/game.rb, line 19 def over? @board.tower(3).full? end
turns()
click to toggle source
# File lib/towers_of_hanoi/game.rb, line 15 def turns @moves.length end