Class: Bridge::Rubber
- Inherits:
-
Array
- Object
- Array
- Bridge::Rubber
- Defined in:
- lib/bridge/result.rb
Overview
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.
Instance Attribute Summary collapse
-
#games ⇒ Object
Returns the value of attribute games.
-
#winner ⇒ Object
Returns the value of attribute winner.
Instance Method Summary collapse
-
#_get_games ⇒ Object
A game is represented as a list of consecutive results from this rubber, coupled with the identifier of the scoring pair.
-
#_get_winner ⇒ Object
The rubber is won by the pair which have completed two games.
Instance Attribute Details
#games ⇒ Object
Returns the value of attribute games.
246 247 248 |
# File 'lib/bridge/result.rb', line 246 def games @games end |
#winner ⇒ Object
Returns the value of attribute winner.
246 247 248 |
# File 'lib/bridge/result.rb', line 246 def winner @winner end |
Instance Method Details
#_get_games ⇒ Object
A game is represented as a list of consecutive results from this rubber, coupled with the identifier of the scoring pair.
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# 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 ⇒ Object
The rubber is won by the pair which have completed two games.
282 283 284 285 286 287 |
# 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 |