20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/mjai/tenpai_analysis.rb', line 20
def waited_pais
raise(ArgumentError, "invalid number of pais") if @pais.size % 3 != 1
raise("not tenpai") if !self.tenpai?
pai_set = Hash.new(0)
for pai in @pais
pai_set[pai.remove_red()] += 1
end
result = []
for mentsus in @shanten.combinations
case mentsus
when :chitoitsu
result.push(pai_set.find(){ |pai, n| n == 1 }[0])
when :kokushimuso
missing = ALL_YAOCHUS - pai_set.keys
if missing.empty?
result += ALL_YAOCHUS
else
result.push(missing[0])
end
else
case mentsus.select(){ |t, ps| t == :toitsu }.size
when 0 (type, pais) = mentsus.find(){ |t, ps| t == :single }
result.push(pais[0])
when 1 (type, pais) = mentsus.find(){ |t, ps| [:ryanpen, :kanta].include?(t) }
relative_numbers = type == :ryanpen ? [-1, 2] : [1]
result += relative_numbers.map(){ |r| pais[0].number + r }.
select(){ |n| (1..9).include?(n) }.
map(){ |n| Pai.new(pais[0].type, n) }
when 2 result += mentsus.select(){ |t, ps| t == :toitsu }.map(){ |t, ps| ps[0] }
else
raise("should not happen")
end
end
end
return result.sort().uniq()
end
|