Sha256: 6786c35ce8b2fa3de84f4f0e20bbc3e21ee2d47aaf3ca3b7382258b4b9444476

Contents?: true

Size: 534 Bytes

Versions: 1

Compression:

Stored size: 534 Bytes

Contents

module TowersOfHanoi
  class Game
    attr_reader :moves, :board

    def initialize(bricks: 3, moves: [])
      @board = TowersOfHanoi::Board.new(bricks: bricks)
      @moves = moves

      @moves.each { |move| move.make(@board) }
    end

    def number_of_bricks
      @board.bricks
    end

    def turns
      @moves.length
    end

    def over?
      @board.tower(3).full?
    end

    def make_move(move)
      @moves << move if move.make(@board)
    end

    def minimum_turns
      2**number_of_bricks - 1
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
towers_of_hanoi-0.1.0 lib/towers_of_hanoi/game.rb