Class: Mjai::Manue::Player::Scene

Inherits:
Object
  • Object
show all
Defined in:
lib/mjai/manue/player.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Scene

Returns a new instance of Scene.



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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/mjai/manue/player.rb', line 20

def initialize(params)
  
  visible_set = params[:visible_set]
  context = params[:context]
  hora_prob_estimator = params[:hora_prob_estimator]
  num_remain_turns = params[:num_remain_turns]
  current_shanten_analysis = params[:current_shanten_analysis]
  furos = params[:furos]
  sutehai_cands = params[:sutehai_cands]
  score_type = params[:score_type]
  @player = params[:player]
  
  tehais = current_shanten_analysis.pais
  scene = hora_prob_estimator.get_scene({
      :visible_set => visible_set,
      :num_remain_turns => num_remain_turns,
      :current_shanten => current_shanten_analysis.shanten,
  })
  
  @evals = {}
  for pai in sutehai_cands
    #p [:pai, pai]
    eval = DahaiEval.new()
    if pai
      idx = tehais.index(pai)
      remains = tehais.dup()
      remains.delete_at(idx)
      shanten_analysis = ShantenAnalysis.new(
          remains, current_shanten_analysis.shanten, [:normal])
      eval.cheapness = pai.type == "t" ? 5 : (5 - pai.number).abs
    else
      remains = tehais
      shanten_analysis = current_shanten_analysis
    end
    # TODO Reuse shanten_analysis
    eval.prob_info = scene.get_tehais(remains)
    eval.points_estimate = HoraPointsEstimate.new({
        :shanten_analysis => shanten_analysis,
        :furos => furos,
        :context => context,
    })
    eval.expected_points =
        eval.points_estimate.average_points * eval.prob_info.hora_prob
    case score_type
      when :expected_points
        eval.score =
            [eval.expected_points, eval.prob_info.progress_prob, eval.cheapness]
      when :progress_prob
        eval.score = [eval.prob_info.progress_prob, eval.cheapness]
      else
        raise("unknown score_type")
    end
    if eval.prob_info.progress_prob > 0.0
      # log("%s: ept=%d ppr=%.3f hpr=%.3f apt=%d (%s)\n" % [
      #     pai,
      #     eval.expected_points,
      #     eval.prob_info.progress_prob,
      #     eval.prob_info.hora_prob,
      #     eval.points_estimate.average_points,
      #     eval.points_estimate.yaku_debug_str,
      # ])
    end
    @evals[pai] = eval
  end
  
  max_score = @evals.values.map(){ |e| e.score }.max
  @best_dahais = @evals.keys.select(){ |pai| @evals[pai].score == max_score }
  @best_dahai = @best_dahais[rand(@best_dahais.size)]
  
end

Instance Attribute Details

#best_dahaiObject (readonly)

Returns the value of attribute best_dahai.



91
92
93
# File 'lib/mjai/manue/player.rb', line 91

def best_dahai
  @best_dahai
end

#best_dahaisObject (readonly)

Returns the value of attribute best_dahais.



91
92
93
# File 'lib/mjai/manue/player.rb', line 91

def best_dahais
  @best_dahais
end

#evalsObject (readonly)

Returns the value of attribute evals.



91
92
93
# File 'lib/mjai/manue/player.rb', line 91

def evals
  @evals
end

Instance Method Details

#log(text) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/mjai/manue/player.rb', line 93

def log(text)
  if @player
    @player.log(text)
  else
    print(text)
  end
end