<commit_before># -*- coding: utf-8 -*-
require 'mlfielib/analysis/pai'
require 'mlfielib/analysis/mentsu'
require 'mlfielib/analysis/tehai'
require 'mlfielib/analysis/kyoku'
require 'mlfielib/analysis/yaku_specimen'

module Mlfielib
  module Analysis
    #############################
    # 得点を計算するクラス          #
    #############################
    class ScoreCalculator
      
      ### 処理結果
      RESULT_SUCCESS          = 0 # 正常終了
      RESULT_ERROR_INTERNAL   = 9 # 不明な内部エラー

    
      # 得点を計算して結果を返す
      def self.calculate_point(tehai, kyoku)
        tehai.fu_num        = self.calc_fu(tehai, kyoku)
        tehai.han_num       = self.calc_han(tehai)
        base_point          = self.calc_base_point(tehai, kyoku)
        tehai.mangan_scale  = self.calc_mangan_scale(base_point, kyoku)
        tehai.child_point   = self.calc_child_point(base_point, kyoku)
        tehai.parent_point  = self.calc_parent_point(base_point, kyoku)
        tehai.total_point   = self.calc_total_point(tehai, kyoku)
        return tehai
      end
    
#      private
#*****************************************************************#
# step1. 符を計算する
#*****************************************************************#
      def self.calc_fu(tehai, kyoku)
        ###--------------- 七対子 ---------------###
        tehai.yaku_list.each do |yaku|
          if yaku.name == YakuSpecimen::YAKU_NAME_CHITOITSU then
             return 25
          end
        end

        ###--------------- 副底 ---------------###
        # 基本符20符 
        total_fu = 20
        
        # 門前で他家から出和了りした場合10符加算
        if !kyoku.is_tsumo then
          menzen_ron = true
          tehai.mentsu_list.each do |mentsu|
            if mentsu.furo then
              menzen_ron = false
            end
          end
          if menzen_ron then
            total_fu += 10
          end
        end
        
        ###--------------- 雀頭 ---------------###
        if tehai.atama.type == Pai::PAI_TYPE_JIHAI
          # 風牌の場合
          if Pai::PAI_NUMBER_TON <= tehai.atama.number && tehai.atama.number <= Pai::PAI_NUMBER_PEI then
            # 自風の計算
            if tehai.atama.number == Pai::PAI_NUMBER_TON && Kyoku::KYOKU_KAZE_TON then
              total_fu += 2
            elsif tehai.atama.number == Pai::PAI_NUMBER_NAN && Kyoku::KYOKU_KAZE_NAN then
              total_fu += 2
            elsif tehai.atama.number == Pai::PAI_NUMBER_SHA && Kyoku::KYOKU_KAZE_SHA then
              total_fu += 2
            elsif tehai.atama.number == Pai::PAI_NUMBER_PEI && Kyoku::KYOKU_KAZE_PEI then
              total_fu += 2
            end
            # 場風の計算
            if tehai.atama.number == Pai::PAI_NUMBER_TON && Kyoku::KYOKU_KAZE_TON then
              total_fu += 2
            elsif tehai.atama.number == Pai::PAI_NUMBER_NAN && Kyoku::KYOKU_KAZE_NAN then
              total_fu += 2
            elsif tehai.atama.number == Pai::PAI_NUMBER_SHA && Kyoku::KYOKU_KAZE_SHA then
              total_fu += 2
            elsif tehai.atama.number == Pai::PAI_NUMBER_PEI && Kyoku::KYOKU_KAZE_PEI then
              total_fu += 2
            end
          # 三元牌の場合
          elsif Pai::PAI_NUMBER_HAKU <= tehai.atama.number && tehai.atama.number <= Pai::PAI_NUMBER_CHUN then
            total_fu += 2
          end
        end
      
        ###--------------- 順子 ---------------###
        # 順子による符の加算は無い

        ###--------------- 刻子 ---------------###
        tehai.mentsu_list.each do |mentsu|
          if mentsu.mentsu_type == Mentsu::MENTSU_TYPE_KOUTSU then
            # 幺九牌の場合
            if mentsu.pai_list[0].yaochu? then
              # 明刻の場合
              if mentsu.furo then
                total_fu += 4
              # 暗刻の場合
              else
                total_fu += 8
              end
            # 中張牌の場合
            else
              # 明刻の場合
              if mentsu.furo then
                total_fu += 2
              # 暗刻の場合
              else
                total_fu += 4
              end
            end
          end
        end
      
        ###--------------- 槓子 ---------------###
        tehai.mentsu_list.each do |mentsu|
          if mentsu.mentsu_type == Mentsu::MENTSU_TYPE_KANTSU then
            # 幺九牌の場合
            if mentsu.pai_list[0].yaochu? then
              # 明刻の場合
              if mentsu.furo then
                total_fu += 16
              # 暗刻の場合
              else
                total_fu += 32
              end
            # 中張牌の場合
            else
              # 明刻の場合
              if mentsu.furo then
                total_fu += 8
              # 暗刻の場合
              else
                total_fu += 16
              end
            end
          end
        end
        
        ###--------------- 待ち形 ---------------###
        # 辺張待ちの場合
        if tehai.penchan_agari? then
          total_fu += 2
        # 嵌張待ちの場合
        elsif tehai.kanchan_agari? then
          total_fu += 2
        # 単騎待ちの場合
        elsif tehai.tanki_agari? then
          total_fu += 2
        end

        ###--------------- 自摸和了 ---------------###
        if kyoku.is_tsumo then
          pinfu_flg = false
          tehai.yaku_list.each do |yaku|
            if yaku.name == YakuSpecimen::YAKU_NAME_PINFU then
              pinfu = true
              break
            end
          end
          if !pinfu_flg then
            total_fu += 2
          end
        end
      
        return self.ceil_one_level(total_fu)
      end
    
#*****************************************************************#
# step2. 飜を計算する
#*****************************************************************#
      def self.calc_han(tehai)
        # 副露があったかどうかを調べる
        menzen_flg = true
        tehai.mentsu_list.each do |mentsu|
          if mentsu.furo then
            menzen_flg = false
            break
          end
        end
        
        total_han = 0
        # 全て門前面子の場合
        if menzen_flg then
          tehai.yaku_list.each do |yaku|
            total_han += yaku.han_num
          end
        # 副露面子を含む場合(食い下がりが発生)
        else
          tehai.yaku_list.each do |yaku|
            total_han += yaku.naki_han_num
          end
        end
        
        return total_han
      end<commit_msg>デバッグ文を追加(最終的には削除する)<commit_after># -*- coding: utf-8 -*-
require 'mlfielib/analysis/pai'
require 'mlfielib/analysis/mentsu'
require 'mlfielib/analysis/tehai'
require 'mlfielib/analysis/kyoku'
require 'mlfielib/analysis/yaku_specimen'

module Mlfielib
  module Analysis
    #############################
    # 得点を計算するクラス          #
    #############################
    class ScoreCalculator
      
      ### 処理結果
      RESULT_SUCCESS          = 0 # 正常終了
      RESULT_ERROR_INTERNAL   = 9 # 不明な内部エラー

    
      # 得点を計算して結果を返す
      def self.calculate_point(tehai, kyoku)
        tehai.fu_num        = self.calc_fu(tehai, kyoku)
        tehai.han_num       = self.calc_han(tehai)
        base_point          = self.calc_base_point(tehai, kyoku)
        tehai.mangan_scale  = self.calc_mangan_scale(base_point, kyoku)
        tehai.child_point   = self.calc_child_point(base_point, kyoku)
        tehai.parent_point  = self.calc_parent_point(base_point, kyoku)
        tehai.total_point   = self.calc_total_point(tehai, kyoku)
        return tehai
      end
    
#      private
#*****************************************************************#
# step1. 符を計算する
#*****************************************************************#
      def self.calc_fu(tehai, kyoku)
        ###--------------- 七対子 ---------------###
        tehai.yaku_list.each do |yaku|
          if yaku.name == YakuSpecimen::YAKU_NAME_CHITOITSU then
             return 25
          end
        end

        ###--------------- 副底 ---------------###
        # 基本符20符 
        total_fu = 20
        
        # 門前で他家から出和了りした場合10符加算
        if !kyoku.is_tsumo then
          menzen_ron = true
          tehai.mentsu_list.each do |mentsu|
            if mentsu.furo then
              menzen_ron = false
            end
          end
          if menzen_ron then
            total_fu += 10
          end
        end
        
        ###--------------- 雀頭 ---------------###
        if tehai.atama.type == Pai::PAI_TYPE_JIHAI
          # 風牌の場合
          if Pai::PAI_NUMBER_TON <= tehai.atama.number && tehai.atama.number <= Pai::PAI_NUMBER_PEI then
            # 自風の計算
            if tehai.atama.number == Pai::PAI_NUMBER_TON && Kyoku::KYOKU_KAZE_TON then
              total_fu += 2
            elsif tehai.atama.number == Pai::PAI_NUMBER_NAN && Kyoku::KYOKU_KAZE_NAN then
              total_fu += 2
            elsif tehai.atama.number == Pai::PAI_NUMBER_SHA && Kyoku::KYOKU_KAZE_SHA then
              total_fu += 2
            elsif tehai.atama.number == Pai::PAI_NUMBER_PEI && Kyoku::KYOKU_KAZE_PEI then
              total_fu += 2
            end
            # 場風の計算
            if tehai.atama.number == Pai::PAI_NUMBER_TON && Kyoku::KYOKU_KAZE_TON then
              total_fu += 2
            elsif tehai.atama.number == Pai::PAI_NUMBER_NAN && Kyoku::KYOKU_KAZE_NAN then
              total_fu += 2
            elsif tehai.atama.number == Pai::PAI_NUMBER_SHA && Kyoku::KYOKU_KAZE_SHA then
              total_fu += 2
            elsif tehai.atama.number == Pai::PAI_NUMBER_PEI && Kyoku::KYOKU_KAZE_PEI then
              total_fu += 2
            end
          # 三元牌の場合
          elsif Pai::PAI_NUMBER_HAKU <= tehai.atama.number && tehai.atama.number <= Pai::PAI_NUMBER_CHUN then
            total_fu += 2
          end
        end
      
        ###--------------- 順子 ---------------###
        # 順子による符の加算は無い

        ###--------------- 刻子 ---------------###
        tehai.mentsu_list.each do |mentsu|
          if mentsu.mentsu_type == Mentsu::MENTSU_TYPE_KOUTSU then
            # 幺九牌の場合
            if mentsu.pai_list[0].yaochu? then
              # 明刻の場合
              if mentsu.furo then
                total_fu += 4
              # 暗刻の場合
              else
                total_fu += 8
              end
            # 中張牌の場合
            else
              # 明刻の場合
              if mentsu.furo then
                total_fu += 2
              # 暗刻の場合
              else
                total_fu += 4
              end
            end
          end
        end
      
        ###--------------- 槓子 ---------------###
        tehai.mentsu_list.each do |mentsu|
          if mentsu.mentsu_type == Mentsu::MENTSU_TYPE_KANTSU then
            # 幺九牌の場合
            if mentsu.pai_list[0].yaochu? then
              # 明刻の場合
              if mentsu.furo then
                total_fu += 16
              # 暗刻の場合
              else
                total_fu += 32
              end
            # 中張牌の場合
            else
              # 明刻の場合
              if mentsu.furo then
                total_fu += 8
              # 暗刻の場合
              else
                total_fu += 16
              end
            end
          end
        end
        
        ###--------------- 待ち形 ---------------###
        # 辺張待ちの場合
        if tehai.penchan_agari? then
          total_fu += 2
        # 嵌張待ちの場合
        elsif tehai.kanchan_agari? then
          total_fu += 2
        # 単騎待ちの場合
        elsif tehai.tanki_agari? then
          total_fu += 2
        end

        ###--------------- 自摸和了 ---------------###
        if kyoku.is_tsumo then
          pinfu_flg = false
          tehai.yaku_list.each do |yaku|
            if yaku.name == YakuSpecimen::YAKU_NAME_PINFU then
              pinfu = true
              break
            end
          end
          if !pinfu_flg then
            total_fu += 2
          end
        end
      
        return self.ceil_one_level(total_fu)
      end
    
#*****************************************************************#
# step2. 飜を計算する
#*****************************************************************#
      def self.calc_han(tehai)
        # 副露があったかどうかを調べる
        menzen_flg = true
        tehai.mentsu_list.each do |mentsu|
          if mentsu.furo then
            menzen_flg = false
            break
          end
        end
        
        total_han = 0
        # 全て門前面子の場合
        if menzen_flg then
          tehai.yaku_list.each do |yaku|
            total_han += yaku.han_num
            STDERR.puts "合計飜:" + total_han.to_s + " 役名:" + yaku.kanji + " 飜数:" + yaku.han_num.to_s + "が加算されました。"
          end
        # 副露面子を含む場合(食い下がりが発生)
        else
          tehai.yaku_list.each do |yaku|
            total_han += yaku.naki_han_num
            STDERR.puts "合計飜:" + total_han.to_s + " 役名:" + yaku.kanji + "(食い下がり) 飜数:" + yaku.naki_han_num.to_s + "が加算されました。"
          end
        end
        
        return total_han
      end
{'fraction_non_alphanumeric': 0.1608159392789374, 'fraction_numerical': 0.006641366223908918, 'mean_word_length': 1.299400109071078, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1678852', 'n_tokens_mistral': 4524, 'n_tokens_neox': 4360, 'n_words': 718}