Sha256: a5de822a45eedeb0c40c6e8bef32a123ad1b95f3f750a3cc1c22929f77675bb2

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

require 'hanoi/jane'

module Hanoi
  module Jane
    class CLI < ::Thor
      desc 'version', 'Print hanoi version'
      def version
        puts 'hanoi version #{VERSION}'
      end
      map %w(-v --version) => :version

      desc 'phat', "Solve the towers against the pHAT's webserver"
      option :phat, type: :string, required: true
      option :constrained, type: :boolean
      option :interval, type: :numeric, default: 0.3

      def phat
        towers = Towers.new 5
        if options[:constrained]
          towers = ConstrainedTowers.new 5
        end

        towers.each do |state|
          Hanoi::Jane.hit_phat towers, options[:phat]
          sleep options[:interval]
        end
      end

      desc 'console', 'Solve the towers on the console'
      option :discs, type: :numeric, default: 3, minimum: 1
      option :constrained, type: :boolean
      option :fancy, type: :boolean, default: false
      def console
        if options[:discs] < 1
          puts "Solving for %d discs makes no sense" % options[:discs]
          exit 1
        end

        towers = Towers.new options[:discs]

        if options[:constrained]
          towers = ConstrainedTowers.new options[:discs]
        end

        towers.fancy = options[:fancy]

        towers.each do |state|
          system('clear')
          s = options[:fancy] ? (Formatters::Console.fancify state.rebased) : state.rebased
          puts s
          puts
          puts state.console
          sleep 0.2
        end

        puts '%d moves to solve for %d discs' % [towers.total, options[:discs]]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hanoi-jane-0.2.3 lib/hanoi/jane/cli.rb