class Tundengine::Stages::Match

Constants

SETTINGS_KEYS

Attributes

settings[R]

Public Class Methods

new(tournament, players, settings) click to toggle source
Calls superclass method Tundengine::Stages::Base::new
# File lib/tundengine/stages/match.rb, line 9
def initialize(tournament, players, settings)
  @players  = players
  @settings = settings
  @trumps   = Deck::SUITS.dup
  @result   = @players.each_with_object({}) { |k, h| h[k] = 0 }
  super(tournament)
end

Public Instance Methods

on_complete_child!(result) click to toggle source
# File lib/tundengine/stages/match.rb, line 27
def on_complete_child!(result)
  update_result!(result)
  rotate_trumps_and_players!
  super()
end
on_completed!() click to toggle source
# File lib/tundengine/stages/match.rb, line 33
def on_completed!
  tournament.on_complete_child!(@result)
end
summary() click to toggle source
# File lib/tundengine/stages/match.rb, line 37
def summary
  {
    settings: settings.each_with_object({}) { |(k,v),h| h[k.to_s] = v.to_s },
    players: @players.map(&:name),
    result:  @result.each_with_object({}) { |(k,v),h| h[k.to_s] = v }
  }
end

Protected Instance Methods

completed?() click to toggle source
# File lib/tundengine/stages/match.rb, line 70
def completed?
  not losers.empty?
end
losers() click to toggle source
# File lib/tundengine/stages/match.rb, line 74
def losers
  @result.select { |_, points| points >= max_points }
end
new_child() click to toggle source
# File lib/tundengine/stages/match.rb, line 47
def new_child
  Round.new(self, players_for_new_round, trump_for_new_round)
end
players_for_new_round() click to toggle source
# File lib/tundengine/stages/match.rb, line 51
def players_for_new_round
  @players.map(&:in_new_round)
end
rotate_trumps_and_players!() click to toggle source
# File lib/tundengine/stages/match.rb, line 66
def rotate_trumps_and_players!
  [@trumps, @players].each { |a| a.rotate! 1 }
end
trump_for_new_round() click to toggle source
# File lib/tundengine/stages/match.rb, line 55
def trump_for_new_round
  @trumps.first
end
update_result!(round_result) click to toggle source
# File lib/tundengine/stages/match.rb, line 59
def update_result!(round_result)
  # these are all match scores, not round points
  @result.merge!(round_result) do |_, acum_score, last_round_score|
    acum_score + last_round_score
  end
end