class Bridge::Rubber

A rubber set, in which pairs compete to make two consecutive games. A game is made by accumulation of 100+ points from below-the-line scores without interruption from an opponent's game.

Attributes

games[RW]
winner[RW]

Public Instance Methods

_get_games() click to toggle source

A game is represented as a list of consecutive results from this rubber, coupled with the identifier of the scoring pair.

# File lib/bridge/result.rb, line 253
def _get_games
  games = []

  thisgame = []
  belowNS, belowEW = 0, 0  # Cumulative totals for results in this game.

  self.each do |result|
    thisgame << result
    if [Direction.north, Direction.south].include?(result.contract.declarer)
      belowNS += result.score[1]
      if belowNS >= 100
        games << [thisgame, [Direction.north, Direction.south]]
      else
        belowEW += result.score[1]
        if belowEW >= 100
          games << [thisgame, [Direction.east, Direction.west]]
        end
      end
      # If either total for this game exceeds 100, proceed to next game.
      if belowNS >= 100 or belowEW >= 100  
        thisgame = []
        belowNS, belowEW = 0, 0  # Reset accumulators.
      end
    end
  end
  return games
end
_get_winner() click to toggle source

The rubber is won by the pair which have completed two games.

# File lib/bridge/result.rb, line 282
def _get_winner
  pairs = self.games.map { |game, pair| pair }
  [[Direction.north, Direction.south], [Direction.east, Direction.west]].each do |pair|
    pair if pairs.count(pair) >= 2
  end
end