Class: Baron::Round::StockRound

Inherits:
Baron::Round show all
Defined in:
lib/baron/round/stock_round.rb

Overview

A stock round in the game

In a stock round phase, players may generally sell many certificates in to the bank pool, and then purchase a single certificate from the initial offering

Instance Attribute Summary

Attributes inherited from Baron::Round

#game

Instance Method Summary collapse

Methods inherited from Baron::Round

#end, #start

Constructor Details

#initialize(game, priority_deal) ⇒ StockRound

Create the stock round

At the start of the stock round the company will ensure that directorships that belong in the initial offering are placed there. It will also make any appropriate non-directors certificates available

Examples:

Baron::InitialAuction.new(game)

Parameters:


22
23
24
25
26
27
28
29
30
# File 'lib/baron/round/stock_round.rb', line 22

def initialize(game, priority_deal)
  @game = game
  @players = game.players.dup
  @players.find_index(priority_deal).times { @players.rotate! }
  @unavailable_certificates_pool = game.unavailable_certificates_pool
  @turns = []
  make_directorships_available
  make_shares_available
end

Instance Method Details

#current_playerBaron::Player

The current player whose turn it is

Examples:

round.current_player

Returns:


39
40
41
# File 'lib/baron/round/stock_round.rb', line 39

def current_player
  current_turn.player
end

#current_turnBaron::Turn::StockTurn

The current stock turn of a player taking their actions

Examples:

round.current_turn

Returns:


50
51
52
53
# File 'lib/baron/round/stock_round.rb', line 50

def current_turn
  @turns << Turn::StockTurn.new(next_player, self) if @turns.all?(&:done?)
  @turns.last
end

#next_priority_dealBaron::Player

Determine who gets priority deal for the next round

Note: This raises an error if the round is not over

Examples:

round.next_priority_deail

Returns:


77
78
79
80
# File 'lib/baron/round/stock_round.rb', line 77

def next_priority_deal
  fail RoundNotOver unless over?
  @turns.last(@players.count).first.player
end

#over?Boolean

Is the current round over?

Examples:

round.over?

Returns:

  • (Boolean)

62
63
64
65
66
# File 'lib/baron/round/stock_round.rb', line 62

def over?
  num_players = @players.count
  @turns.count >= num_players &&
    @turns.last(num_players).all?(&:passed?)
end