Skip to content

Commit

Permalink
Console now excellent
Browse files Browse the repository at this point in the history
  • Loading branch information
pikesley committed Jan 20, 2018
1 parent 33d9302 commit e7780bd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions lib/hanoi/jane/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,39 @@ def phat
sleep interval
end
end

desc 'console', 'Solve the towers on the console'
option :discs, type: :numeric, default: 3
option :constrained, type: :boolean, default: true
option :interval, type: :numeric, default: 0.5
option :height, type: :numeric, default: 2

def console
at = AnimatedTowers.new do |a|
a.towers = options[:constrained] ? ConstrainedTowers : Towers
a.discs = options[:discs]
a.height = options[:discs] + options[:height]
end

at.each do |frame|
system('clear')

c = Formatters::Console.new do |c|
c.stacks = frame.stacks
end

puts frame.value
puts c

interval = options[:interval]
if frame.type == :tween
interval = interval * 0.1
end
sleep interval
end

puts '%d moves to solve for %d discs' % [at.towers.total, at.discs]
end
end
end
end
2 changes: 1 addition & 1 deletion lib/hanoi/jane/formatters/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize
end

def to_s
require "pry" ; binding.pry
(Console.assemble stacks).map { |r| r.join '' }.join "\n"
end

def Console.assemble stacks
Expand Down

0 comments on commit e7780bd

Please sign in to comment.