# frozen-string-literal: true

# Swars::User::Stat::FrequencyExtractor.high_accuracy
# >> |-----|
# >> | 515 |
# >> |-----|
# >> |-----+-----------------------|
# >> | key | ratio                 |
# >> |-----+-----------------------|
# >> | 杏  | 0.0012432623567665045 |
# >> | 全  |  0.002663247067491629 |
# >> | 圭  | 0.0026711358306407544 |
# >> | と  |  0.009093115889395976 |
# >> | 龍  |  0.017298266838485784 |
# >> | 馬  |  0.019454151941932046 |
# >> | 香  |  0.023406805585627757 |
# >> | 桂  |   0.06559815350942172 |
# >> | 玉  |   0.08727810239208346 |
# >> | 角  |   0.09229347386967632 |
# >> | 飛  |   0.09975018682220436 |
# >> | 金  |    0.1051636332294009 |
# >> | 銀  |    0.1780809228105882 |
# >> | 歩  |    0.2960055418562846 |
# >> |-----+-----------------------|
# >> [{:key=>"杏", :ratio=>0.0012432623567665045},
# >>  {:key=>"全", :ratio=>0.002663247067491629},
# >>  {:key=>"圭", :ratio=>0.0026711358306407544},
# >>  {:key=>"と", :ratio=>0.009093115889395976},
# >>  {:key=>"龍", :ratio=>0.017298266838485784},
# >>  {:key=>"馬", :ratio=>0.019454151941932046},
# >>  {:key=>"香", :ratio=>0.023406805585627757},
# >>  {:key=>"桂", :ratio=>0.06559815350942172},
# >>  {:key=>"玉", :ratio=>0.08727810239208346},
# >>  {:key=>"角", :ratio=>0.09229347386967632},
# >>  {:key=>"飛", :ratio=>0.09975018682220436},
# >>  {:key=>"金", :ratio=>0.1051636332294009},
# >>  {:key=>"銀", :ratio=>0.1780809228105882},
# >>  {:key=>"歩", :ratio=>0.2960055418562846}]

module Swars
  module User::Stat
    class FreqPieceInfo
      include ApplicationMemoryRecord
      memory_record [
        { key: "杏", ratio: 0.0012432623567665045, },
        { key: "全", ratio: 0.002663247067491629,  },
        { key: "圭", ratio: 0.0026711358306407544, },
        { key: "と", ratio: 0.009093115889395976,  },
        { key: "龍", ratio: 0.017298266838485784,  },
        { key: "馬", ratio: 0.019454151941932046,  },
        { key: "香", ratio: 0.023406805585627757,  },
        { key: "桂", ratio: 0.06559815350942172,   },
        { key: "玉", ratio: 0.08727810239208346,   },
        { key: "角", ratio: 0.09229347386967632,   },
        { key: "飛", ratio: 0.09975018682220436,   },
        { key: "金", ratio: 0.1051636332294009,    },
        { key: "銀", ratio: 0.1780809228105882,    },
        { key: "歩", ratio: 0.2960055418562846,    },
      ]

      def two_char_key
        @two_char_key ||= yield_self do
          [
            Bioshogi::Piece.fetch(name).sfen_char,
            Bioshogi::Piece.basic_group[name] ? 0 : 1,
          ].join
        end
      end
    end
  end
end
