Class: Mjai::Hora
- Inherits:
-
Object
- Object
- Mjai::Hora
- Extended by:
- Forwardable, WithFields
- Defined in:
- lib/mjai/hora.rb
Defined Under Namespace
Classes: Candidate, Mentsu, PointsDatum
Constant Summary collapse
- FURO_TYPE_TO_MENTSU_TYPE =
{ :chi => :shuntsu, :pon => :kotsu, :daiminkan => :kantsu, :kakan => :kantsu, :ankan => :kantsu, }
- BASE_FU_MAP =
{ :shuntsu => 0, :kotsu => 2, :kantsu => 8, }
- GREEN_PAIS =
Set.new(Pai.parse_pais("23468sF"))
- CHURENPOTON_NUMBERS =
[1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9]
- YAKUMAN_FAN =
100
Instance Attribute Summary collapse
-
#all_pais ⇒ Object
readonly
Returns the value of attribute all_pais.
-
#free_pais ⇒ Object
readonly
Returns the value of attribute free_pais.
-
#num_akadoras ⇒ Object
readonly
Returns the value of attribute num_akadoras.
-
#num_doras ⇒ Object
readonly
Returns the value of attribute num_doras.
-
#num_uradoras ⇒ Object
readonly
Returns the value of attribute num_uradoras.
Attributes included from WithFields
Instance Method Summary collapse
- #count_doras(target_doras) ⇒ Object
-
#initialize(params) ⇒ Hora
constructor
A new instance of Hora.
Methods included from WithFields
Constructor Details
#initialize(params) ⇒ Hora
Returns a new instance of Hora.
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
# File 'lib/mjai/hora.rb', line 493 def initialize(params) @fields = params raise("tehais is missing") if !self.tehais raise("taken is missing") if !self.taken @free_pais = self.tehais + [self.taken] @all_pais = @free_pais + self.furos.map(){ |f| f.pais }.flatten() @num_doras = count_doras(self.doras) @num_uradoras = count_doras(self.uradoras) @num_akadoras = @all_pais.select(){ |pai| pai.red? }.size num_same_as_taken = @free_pais.select(){ |pai| pai.same_symbol?(self.taken) }.size @shanten = ShantenAnalysis.new(@free_pais, -1) raise("not hora") if @shanten.shanten > -1 unflatten_cands = @shanten.combinations.map() do |c| (0...num_same_as_taken).map(){ |i| Candidate.new(self, c, i) } end @candidates = unflatten_cands.flatten() @best_candidate = @candidates.max_by(){ |c| c.points } end |
Instance Attribute Details
#all_pais ⇒ Object (readonly)
Returns the value of attribute all_pais.
517 518 519 |
# File 'lib/mjai/hora.rb', line 517 def all_pais @all_pais end |
#free_pais ⇒ Object (readonly)
Returns the value of attribute free_pais.
517 518 519 |
# File 'lib/mjai/hora.rb', line 517 def free_pais @free_pais end |
#num_akadoras ⇒ Object (readonly)
Returns the value of attribute num_akadoras.
517 518 519 |
# File 'lib/mjai/hora.rb', line 517 def num_akadoras @num_akadoras end |
#num_doras ⇒ Object (readonly)
Returns the value of attribute num_doras.
517 518 519 |
# File 'lib/mjai/hora.rb', line 517 def num_doras @num_doras end |
#num_uradoras ⇒ Object (readonly)
Returns the value of attribute num_uradoras.
517 518 519 |
# File 'lib/mjai/hora.rb', line 517 def num_uradoras @num_uradoras end |
Instance Method Details
#count_doras(target_doras) ⇒ Object
521 522 523 524 |
# File 'lib/mjai/hora.rb', line 521 def count_doras(target_doras) return @all_pais.map(){ |pai| target_doras.select(){ |d| d.same_symbol?(pai) }.size }. inject(0, :+) end |