lib/combinatorial_puzzle_solver/puzzle.rb
# Resolves a puzzle while writing diagnostic output to given streams.
#
# @param trial_and_error [Boolean] whether it should resort to trial and error if
#                                  a complete solution cannot be resolved.
# @param steps [Fixnum] how many steps it will perform before aborting (or 0).
# @param output [Hash] a collection of output streams for diagnostic purposes.
# @return [true,false] whether the puzzle was completely resolved or not.
# @raise [Inconsistency] if the solution space becomes inconsistent without any
#                         possible solution.
Resolves a puzzle while writing diagnostic output to given streams.
Resolves a puzzle while writing diagnostic output to given streams .
def resolve!(trial_and_error=true, steps=0, output={})
      output[:parsed_stream].puts to_s << "\n\n" if output[:parsed_stream]
      step_count = 0
      solution = SolutionSpace.new(self)
      solution.resolve!(solution.resolved_identifiers){|x, identifier, value|
        identifier.set!(value)
        output[:steps_stream].puts identifier.inspect if output[:steps_stream]
        output[:puzzle_stream].puts to_s << "\n\n" if output[:puzzle_stream]
        step_count += 1
        step_count != steps
      }
      brute_forced = solution.resolve_by_trial_and_error! if trial_and_error
      solution = brute_forced unless brute_forced.nil?
      set_resolved_identifiers!(solution)
      output[:result_stream].puts to_s << "\n\n" if output[:result_stream]
      solution.resolved?
    end
def resolve! ( trial_and_error = true , steps = 0 , output = { } ) output [ :parsed_stream ] . puts to_s << "\n\n" if output [ :parsed_stream ] step_count = 0 solution = SolutionSpace . new ( self ) solution . resolve! ( solution . resolved_identifiers ) { | x , identifier , value | identifier . set! ( value ) output [ :steps_stream ] . puts identifier . inspect if output [ :steps_stream ] output [ :puzzle_stream ] . puts to_s << "\n\n" if output [ :puzzle_stream ] step_count += 1 step_count != steps } brute_forced = solution . resolve_by_trial_and_error! if trial_and_error solution = brute_forced unless brute_forced . nil? set_resolved_identifiers! ( solution ) output [ :result_stream ] . puts to_s << "\n\n" if output [ :result_stream ] solution . resolved? end
Resolves a puzzle while writing diagnostic output to given streams.
Resolves a puzzle while writing diagnostic output to given streams .
# print the parsed puzzle # print the resolved step # print the entire board # brute force with trial and error unless we only want the resolution steps # print the result
whether the puzzle was completely resolved or not.
whether the puzzle was completely resolved or not .
true,false
[Inconsistency] if the solution space becomes inconsistent without any possible solution.
[ Inconsistency ] if the solution space becomes inconsistent without any possible solution .
trial_and_error
whether it should resort to trial and error if a complete solution cannot be resolved.
whether it should resort to trial and error if a complete solution cannot be resolved .
steps
None
output
a collection of output streams for diagnostic purposes.
a collection of output streams for diagnostic purposes .