Sha256: 860bc476514945693d2adf636b7be0a58513a755916431c3a6c9740cde56c73f

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 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

        until towers.solved do
          Hanoi::Jane.hit_phat towers, options[:phat]
          towers.move
          sleep options[:interval]
        end
        Hanoi::Jane.hit_phat towers, options[:phat]
      end

      desc 'console', "Solve the towers one the console"
      option :discs, type: :numeric, default: 3
      option :constrained, type: :boolean
      def console
        towers = Towers.new options[:discs]
        if options[:constrained]
          towers = ConstrainedTowers.new options[:discs]
        end
        until towers.solved do
          puts towers
          towers.move
        end
        puts towers

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

Version data entries

1 entries across 1 versions & 1 rubygems

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