Class: TenpaiWakaruMan::Calculator

Inherits:
Object
  • Object
show all
Defined in:
lib/tenpai_wakaru_man/calculator.rb

Defined Under Namespace

Classes: HanCounter

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCalculator

Returns a new instance of Calculator.



12
13
# File 'lib/tenpai_wakaru_man/calculator.rb', line 12

def initialize
end

Class Method Details

.calculate(tiles) ⇒ Object



7
8
9
# File 'lib/tenpai_wakaru_man/calculator.rb', line 7

def calculate(tiles)
  new.calculate(tiles)
end

Instance Method Details

#calculate(tiles, options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tenpai_wakaru_man/calculator.rb', line 15

def calculate(tiles, options = {})
  return nil if (hands = Parser.parse(tiles).winning_hands).empty?

  hands.map {|hand|
    options[:tsumo_or_ron] = :ron

    fu = FuCounter.count(hand)
    han = HanCounter.count(hand)

    {fu: fu, han: han, ten: TEN[han.size][fu][options[:tsumo_or_ron].to_s]}
  }.max {|hash| hash[:ten] }
end