Class: Mjai::ShantenPlayer
Instance Attribute Summary
Attributes inherited from Player
#attributes, #extra_anpais, #furos, #game, #ho, #id, #name, #reach_ho_index, #reach_state, #score, #sutehais, #tehais
Instance Method Summary collapse
-
#initialize(params) ⇒ ShantenPlayer
constructor
A new instance of ShantenPlayer.
- #respond_to_action(action) ⇒ Object
Methods inherited from Player
#anpais, #can_hora?, #can_reach?, #can_ryukyoku?, #context, #create_action, #delete_tehai, #double_reach?, #furiten?, #get_pais_combinations, #inspect, #ippatsu_chance?, #jikaze, #kuikae_dahais, #possible_actions, #possible_dahais, #possible_dahais_after_furo, #possible_furo_actions, #rank, #reach?, #rinshan?, #tenpai?, #update_state
Constructor Details
#initialize(params) ⇒ ShantenPlayer
Returns a new instance of ShantenPlayer.
10 11 12 13 |
# File 'lib/mjai/shanten_player.rb', line 10 def initialize(params) super() @use_furo = params[:use_furo] end |
Instance Method Details
#respond_to_action(action) ⇒ Object
15 16 17 18 19 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 90 91 |
# File 'lib/mjai/shanten_player.rb', line 15 def respond_to_action(action) if action.actor == self case action.type when :tsumo, :chi, :pon, :reach current_shanten_analysis = ShantenAnalysis.new(self.tehais, nil, [:normal]) current_shanten = current_shanten_analysis.shanten if can_hora?(current_shanten_analysis) if @use_furo return create_action({:type => :dahai, :pai => action.pai, :tsumogiri => true}) else return create_action({ :type => :hora, :target => action.actor, :pai => action.pai, }) end elsif can_reach?(current_shanten_analysis) return create_action({:type => :reach}) elsif self.reach? return create_action({:type => :dahai, :pai => action.pai, :tsumogiri => true}) end # Ankan, kakan furo_actions = self.possible_furo_actions if !furo_actions.empty? return furo_actions[0] end sutehai_cands = [] for pai in self.possible_dahais remains = self.tehais.dup() remains.delete_at(self.tehais.index(pai)) if ShantenAnalysis.new(remains, current_shanten, [:normal]).shanten == current_shanten sutehai_cands.push(pai) end end if sutehai_cands.empty? sutehai_cands = self.possible_dahais end #log("sutehai_cands = %p" % [sutehai_cands]) sutehai = sutehai_cands[rand(sutehai_cands.size)] tsumogiri = [:tsumo, :reach].include?(action.type) && sutehai == self.tehais[-1] return create_action({:type => :dahai, :pai => sutehai, :tsumogiri => tsumogiri}) end else # action.actor != self case action.type when :dahai if self.can_hora? if @use_furo return nil else return create_action({ :type => :hora, :target => action.actor, :pai => action.pai, }) end elsif @use_furo furo_actions = self.possible_furo_actions if !furo_actions.empty? return furo_actions[0] end end end end return nil end |