diff --git a/lib/hanoi/jane.rb b/lib/hanoi/jane.rb index e984296..b623ab4 100644 --- a/lib/hanoi/jane.rb +++ b/lib/hanoi/jane.rb @@ -9,7 +9,6 @@ require 'hanoi/jane/config' require 'hanoi/jane/exceptions' -require 'hanoi/jane/towers/stack_finders' require 'hanoi/jane/towers/regular_towers' require 'hanoi/jane/towers/constrained_towers' require 'hanoi/jane/towers/animated_towers' diff --git a/lib/hanoi/jane/towers/constrained_towers.rb b/lib/hanoi/jane/towers/constrained_towers.rb index 58757ef..94068a6 100644 --- a/lib/hanoi/jane/towers/constrained_towers.rb +++ b/lib/hanoi/jane/towers/constrained_towers.rb @@ -1,8 +1,6 @@ module Hanoi module Jane class ConstrainedTowers < RegularTowers - extend ConstrainedStackFinder - def initialize discs = 3 super @base = 3 @@ -17,6 +15,20 @@ def inspect i[:ternary] = i.delete :binary i end + + def ConstrainedTowers.find_stack stacks:, from:, disc: nil, total: + # if we're in the middle + if from == 1 + # we always move to the right on an even total + if total % 2 == 0 + return 2 + else + return 0 + end + end + # otherwise we're at the edges and can only move to the middle + 1 + end end end end diff --git a/lib/hanoi/jane/towers/regular_towers.rb b/lib/hanoi/jane/towers/regular_towers.rb index fa09615..9091661 100644 --- a/lib/hanoi/jane/towers/regular_towers.rb +++ b/lib/hanoi/jane/towers/regular_towers.rb @@ -3,8 +3,6 @@ module Jane class RegularTowers include Enumerable - extend StackFinder - attr_reader :total, :base, :disc, :from, :to, :discs attr_accessor :stacks @@ -88,6 +86,21 @@ def rebased self.class.rebase @total, @base, @discs end + def RegularTowers.find_stack stacks:, from:, disc:, total: nil + # if the next stack is empty, move there + if stacks[(from + 1) % 3] == [] + return (from + 1) % 3 + end + + # if the next stack has a smaller top disc than our disc, go one more over + if stacks[(from + 1) % 3][-1] < disc + return (from + 2) % 3 + end + + # default to the next one + (from + 1) % 3 + end + def RegularTowers.starter_stacks discs [(0...discs).to_a.reverse, [], []] end diff --git a/lib/hanoi/jane/towers/stack_finders.rb b/lib/hanoi/jane/towers/stack_finders.rb deleted file mode 100644 index 8e19bdd..0000000 --- a/lib/hanoi/jane/towers/stack_finders.rb +++ /dev/null @@ -1,36 +0,0 @@ -module Hanoi - module Jane - module StackFinder - def find_stack stacks:, from:, disc:, total: nil - # if the next stack is empty, move there - if stacks[(from + 1) % 3] == [] - return (from + 1) % 3 - end - - # if the next stack has a smaller top disc than our disc, go one more over - if stacks[(from + 1) % 3][-1] < disc - return (from + 2) % 3 - end - - # default to the next one - return (from + 1) % 3 - end - end - - module ConstrainedStackFinder - def find_stack stacks:, from:, disc: nil, total: - # if we're in the middle - if from == 1 - # we always move to the right on an even total - if total % 2 == 0 - return 2 - else - return 0 - end - end - # otherwise we're at the edges and can only move to the middle - 1 - end - end - end -end diff --git a/lib/hanoi/jane/version.rb b/lib/hanoi/jane/version.rb index 949930c..b703e27 100644 --- a/lib/hanoi/jane/version.rb +++ b/lib/hanoi/jane/version.rb @@ -1,5 +1,5 @@ module Hanoi module Jane - VERSION = '0.3.2' + VERSION = '0.3.3' end end