Class: Mjai::Manue::HoraPointsEstimate::HoraCombination
- Inherits:
-
Object
- Object
- Mjai::Manue::HoraPointsEstimate::HoraCombination
- Defined in:
- lib/mjai/manue/hora_points_estimate.rb
Instance Attribute Summary collapse
-
#janto_candidates ⇒ Object
readonly
Returns the value of attribute janto_candidates.
-
#mentsu_candidates ⇒ Object
readonly
Returns the value of attribute mentsu_candidates.
-
#used_combination ⇒ Object
readonly
Returns the value of attribute used_combination.
Instance Method Summary collapse
- #akadora_pfan ⇒ Object
- #dora_pfan ⇒ Object
- #fanpai_pfan ⇒ Object
- #get_dora_fan(mentsu) ⇒ Object
- #get_fanpai_prob(mentsu_cands, fan) ⇒ Object
- #get_iso_prob(types) ⇒ Object
- #get_prob(mentsu_cands, &block) ⇒ Object
-
#get_ryanmen_prob(mentsu) ⇒ Object
Assuming the mentsu becomes shuntsu in the end, returns the probability that its waiting form is ryanmen.
- #has_yaochu?(mentsu) ⇒ Boolean
-
#initialize(used_combination, hp_est) ⇒ HoraCombination
constructor
A new instance of HoraCombination.
- #iso_pfan ⇒ Object
- #pinfu_pfan ⇒ Object
- #reach_pfan ⇒ Object
- #tanyaochu_pfan ⇒ Object
- #yaku_pfan(yaku) ⇒ Object
Constructor Details
#initialize(used_combination, hp_est) ⇒ HoraCombination
Returns a new instance of HoraCombination.
81 82 83 84 85 86 87 88 89 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 81 def initialize(used_combination, hp_est) @used_combination = used_combination @hp_est = hp_est @janto_candidates = HoraPointsEstimate.janto_candidates(@used_combination.janto) @mentsu_candidates = @used_combination.mentsus.map() do |mentsu| HoraPointsEstimate.complete_candidates(mentsu) end @menzen = @used_combination.mentsus.all?(){ |m| m.visibility == :an } end |
Instance Attribute Details
#janto_candidates ⇒ Object (readonly)
Returns the value of attribute janto_candidates.
92 93 94 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 92 def janto_candidates @janto_candidates end |
#mentsu_candidates ⇒ Object (readonly)
Returns the value of attribute mentsu_candidates.
93 94 95 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 93 def mentsu_candidates @mentsu_candidates end |
#used_combination ⇒ Object (readonly)
Returns the value of attribute used_combination.
91 92 93 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 91 def used_combination @used_combination end |
Instance Method Details
#akadora_pfan ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 182 def akadora_pfan # Note that red is removed from @mentsu_candidates etc. red_pais = @hp_est.shanten_analysis.pais. select(){ |pai| pai.red? }. map(){ |pai| pai.remove_red() } pfan = ProbablisticFan.new(0) for red_pai in red_pais neg_prob = 1.0 for cands in [@janto_candidates] + @mentsu_candidates neg_prob *= get_prob(cands){ |m| !m.pais.any?(){ |pai| red_pais.include?(pai) } } end pfan += ProbablisticFan.new({0 => neg_prob, 1 => 1.0 - neg_prob}) end return pfan end |
#dora_pfan ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 170 def dora_pfan pfan = ProbablisticFan.new(0) for cands in [@janto_candidates] + @mentsu_candidates probs = Hash.new(0.0) for mentsu, prob in cands probs[get_dora_fan(mentsu)] += prob end pfan += ProbablisticFan.new(probs) end return pfan end |
#fanpai_pfan ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 156 def fanpai_pfan pfan = ProbablisticFan.new(0) for cands in @mentsu_candidates fan1_prob = get_fanpai_prob(cands, 1) fan2_prob = get_fanpai_prob(cands, 2) pfan += ProbablisticFan.new({ 0 => 1.0 - fan1_prob - fan2_prob, 1 => fan1_prob, 2 => fan2_prob, }) end return pfan end |
#get_dora_fan(mentsu) ⇒ Object
213 214 215 216 217 218 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 213 def get_dora_fan(mentsu) fans = mentsu.pais.map() do |pai| @hp_est.context.doras.count(pai.remove_red()) end return fans.inject(0, :+) end |
#get_fanpai_prob(mentsu_cands, fan) ⇒ Object
207 208 209 210 211 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 207 def get_fanpai_prob(mentsu_cands, fan) return get_prob(mentsu_cands) do |m| m.type == :kotsu && @hp_est.context.fanpai_fan(m.pais[0]) == fan end end |
#get_iso_prob(types) ⇒ Object
147 148 149 150 151 152 153 154 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 147 def get_iso_prob(types) prob = 1.0 prob *= get_prob(@janto_candidates){ |m| types.include?(m.pais[0].type) } for cands in @mentsu_candidates prob *= get_prob(cands){ |m| types.include?(m.pais[0].type) } end return prob end |
#get_prob(mentsu_cands, &block) ⇒ Object
203 204 205 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 203 def get_prob(mentsu_cands, &block) return mentsu_cands.select(){ |m, pr| yield(m) }.map(){ |m, pr| pr }.inject(0.0, :+) end |
#get_ryanmen_prob(mentsu) ⇒ Object
Assuming the mentsu becomes shuntsu in the end, returns the probability that its waiting form is ryanmen.
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 222 def get_ryanmen_prob(mentsu) case mentsu.type when :ryanmen return 1.0 when :kanta, :penta return 0.0 when :single case mentsu.pais[0].number when 1, 9 return 0.0 when 2, 8 # [3] out of [1, 3, 4] return 1.0 / 3.0 else # [2, 4] out of [1, 2, 4, 5] return 0.5 end else raise("should not happen: %p" % mentsu.type) end end |
#has_yaochu?(mentsu) ⇒ Boolean
199 200 201 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 199 def has_yaochu?(mentsu) return mentsu.pais.any?(){ |pai| pai.yaochu? } end |
#iso_pfan ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 132 def iso_pfan pfan = ProbablisticFan.new(0) for type in ["m", "p", "s"] chiniso_prob = get_iso_prob([type]) honiso_prob = get_iso_prob([type, "t"]) - chiniso_prob type_prob = ProbablisticFan.new({ 0 => 1.0 - honiso_prob - chiniso_prob, (@menzen ? 3 : 2) => honiso_prob, (@menzen ? 6 : 5) => chiniso_prob, }) pfan = pfan.max(type_prob) end return pfan end |
#pinfu_pfan ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 111 def pinfu_pfan if @menzen prob = 1.0 prob *= get_prob(@janto_candidates) do |m| @hp_est.context.fanpai_fan(m.pais[0]) == 0 end for cands in @mentsu_candidates prob *= get_prob(cands){ |m| m.type == :shuntsu } end if prob > 0.0 incompletes = @used_combination.mentsus.select(){ |m| m.pais.size < 3 } ryanmen_prob = incompletes.map(){ |m| get_ryanmen_prob(m) }.inject(0.0, :+) / incompletes.size prob *= ryanmen_prob end else prob = 0.0 end return ProbablisticFan.new({0 => 1.0 - prob, 1 => prob}) end |
#reach_pfan ⇒ Object
99 100 101 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 99 def reach_pfan return ProbablisticFan.new(@menzen ? 1 : 0) end |
#tanyaochu_pfan ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 103 def tanyaochu_pfan prob = 1.0 for cands in [@janto_candidates] + @mentsu_candidates prob *= get_prob(cands){ |m| !has_yaochu?(m) } end return ProbablisticFan.new({0 => 1.0 - prob, 1 => prob}) end |
#yaku_pfan(yaku) ⇒ Object
95 96 97 |
# File 'lib/mjai/manue/hora_points_estimate.rb', line 95 def yaku_pfan(yaku) return __send__("#{yaku}_pfan") end |