Class: Baron::Turn::StockTurn

Inherits:
Baron::Turn show all
Defined in:
lib/baron/turn/stock_turn.rb

Overview

A stock turn is a single players turn to sell and buy certificates

In most games, a player may sell as many certificats as they would like to the bank pool (respecting various limits). And then buy one certificate. A player may also pass and take no action.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Baron::Turn

#perform

Constructor Details

#initialize(player, round) ⇒ StockTurn

Create the stock turn

Examples:

Baron::Turn::StockTurn.new(player, round)

Parameters:


36
37
38
39
40
41
# File 'lib/baron/turn/stock_turn.rb', line 36

def initialize(player, round)
  @player = player
  @round = round
  @done = false
  @passed = false
end

Instance Attribute Details

#playerBaron::Player (readonly)

The player who is taking the turn

Examples:

stock_turn.player

Returns:


17
18
19
# File 'lib/baron/turn/stock_turn.rb', line 17

def player
  @player
end

#roundBaron::StockRound (readonly)

The stock round in which this stock turn is taking place

Examples:

stock_turn.round

Returns:

  • (Baron::StockRound)

26
27
28
# File 'lib/baron/turn/stock_turn.rb', line 26

def round
  @round
end

Instance Method Details

#available_actionsArray<Baron::Action>

Returns a list of actions that the player can take

Examples:

turn.available_actions

Returns:


77
78
79
80
81
82
83
84
# File 'lib/baron/turn/stock_turn.rb', line 77

def available_actions
  [
    Action::BuyCertificate,
    Action::Pass,
    Action::SellCertificates,
    Action::StartCompany
  ]
end

#buycertificate(action) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

The player buys the certifiate from a source

The player will buy the certificate at the appropriate price determined by the par price or market price for that certificate

Parameters:


94
95
96
97
98
# File 'lib/baron/turn/stock_turn.rb', line 94

def buycertificate(action)
  @done = true
  action.create_transaction
  check_for_float action.certificate.company
end

#done?Boolean

Is this stock turn over?

The persons stock turn is over if they have passed, or if they have done their purchase for the round.

Examples:

turn.done?

Returns:

  • (Boolean)

    Returns true if this turn is done, false otherwise


53
54
55
# File 'lib/baron/turn/stock_turn.rb', line 53

def done?
  @done
end

#pass(_) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

The player passes

The player will be done, and they can not take any more actions on this turn

Parameters:


108
109
110
111
# File 'lib/baron/turn/stock_turn.rb', line 108

def pass(_)
  @passed = true
  @done = true
end

#passed?Boolean

Was this action a pass?

A pass is defined as taking no buy, or sell actions

Examples:

turn.pass?

Returns:

  • (Boolean)

    True if this was a pass, false otherwise


66
67
68
# File 'lib/baron/turn/stock_turn.rb', line 66

def passed?
  @passed
end

#sellcertificates(action) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

The player sells one or more certificates

This creates the transaction which transfers the certificates to the bank in exchange for money.

Parameters:


121
122
123
# File 'lib/baron/turn/stock_turn.rb', line 121

def sellcertificates(action)
  action.create_transaction
end

#startcompany(action) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

The player starts a new company

This sets up the par price, and transfers the directors certificate to the player in exchange for the appropriate amount of money

Parameters:


133
134
135
136
# File 'lib/baron/turn/stock_turn.rb', line 133

def startcompany(action)
  @done = true
  action.setup
end