Class: Numeron::Solver
- Inherits:
-
Object
- Object
- Numeron::Solver
- Defined in:
- lib/numeron/solver.rb
Instance Attribute Summary collapse
-
#calc ⇒ Object
Returns the value of attribute calc.
-
#card_size ⇒ Object
Returns the value of attribute card_size.
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize ⇒ Solver
constructor
A new instance of Solver.
- #question ⇒ Object
- #run ⇒ Object
- #think ⇒ Object
Constructor Details
#initialize ⇒ Solver
Returns a new instance of Solver.
6 7 8 9 |
# File 'lib/numeron/solver.rb', line 6 def initialize @calc = Numeron::Calculator.new @card_size = 3 end |
Instance Attribute Details
#calc ⇒ Object
Returns the value of attribute calc.
5 6 7 |
# File 'lib/numeron/solver.rb', line 5 def calc @calc end |
#card_size ⇒ Object
Returns the value of attribute card_size.
5 6 7 |
# File 'lib/numeron/solver.rb', line 5 def card_size @card_size end |
Instance Method Details
#finish ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/numeron/solver.rb', line 76 def finish while 1 print "\nfinish? [yes|no] " f = STDIN.gets.chomp if(f == 'yes' || f == 'y') exit elsif f == 'no' || f == 'n' break end end end |
#question ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/numeron/solver.rb', line 19 def question attack_number = nil eat = 0 bite = 0 while 1 print "Attack number: " attack_number = STDIN.gets.chomp if @card_size == attack_number.split(//).size break else puts 'Required ' + @card_size.to_s + ' digits.' end end while 1 while 1 print "Eat number: " eat = STDIN.gets.chomp.to_i if @card_size > eat break else puts 'Required less than ' + @card_size.to_s + ' digits.' end end while 1 print "Bite number: " bite = STDIN.gets.chomp.to_i if @card_size >= bite break else print 'Required ' + @card_size.to_s + ' digits or less' end end if eat + bite <= @card_size break else puts "Error, Eat + Bite > " + @card_size.to_s end end @calc.input(attack_number, eat, bite) end |
#run ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/numeron/solver.rb', line 11 def run while 1 next unless question think finish end end |
#think ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/numeron/solver.rb', line 63 def think puts "... thinking" puts "possibilities: " + @calc.possibilities.size.to_s analyzer = Numeron::Analyzer.new(@calc) result = @calc.possibilities.size <= 64 ? analyzer.run(:possibilities) : analyzer.run(:average) if result[:recommend].size > 0 puts "Analyzer Answer: " + result[:recommend].sample.to_s else puts "Calculator Error." end puts "Possibilitiy list random: " + @calc.possibilities.sample.to_s end |