Class: TenpaiWakaruMan::Calculator
- Inherits:
-
Object
- Object
- TenpaiWakaruMan::Calculator
- Defined in:
- lib/tenpai_wakaru_man/calculator.rb
Defined Under Namespace
Classes: HanCounter
Class Method Summary collapse
Instance Method Summary collapse
- #calculate(tiles, options = {}) ⇒ Object
-
#initialize ⇒ Calculator
constructor
A new instance of Calculator.
Constructor Details
#initialize ⇒ Calculator
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, = {}) return nil if (hands = Parser.parse(tiles).winning_hands).empty? hands.map {|hand| [:tsumo_or_ron] = :ron fu = FuCounter.count(hand) han = HanCounter.count(hand) {fu: fu, han: han, ten: TEN[han.size][fu][[:tsumo_or_ron].to_s]} }.max {|hash| hash[:ten] } end |