Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/engine/game/g_18_india/step/sell_once_then_buy_certs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def can_buy_company?(entity, company)
return false if @game.in_ipo?(company) && !can_buy_from_ipo?(entity, company)
return false if current_entity.hand.include?(company) && !can_buy_from_hand?(entity, company)

(available_cash(entity) >= company.value)
price = current_entity.hand.include?(company) ? hand_price(company) : company.value
(available_cash(entity) >= price)
end

def can_buy_from_market?(entity, company)
Expand All @@ -196,10 +197,20 @@ def can_buy_from_hand?(entity, company)
prior.name == company.name
end
else
(available_cash(entity) >= company.value)
(available_cash(entity) >= hand_price(company))
end
end

def hand_price(company)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strongly recommend: Add state-based fixture test

Since 18India has existing fixtures, please add a test that verifies:

  1. A player can buy a hand share certificate at IPO price when corporation's market price is above IPO price
  2. A player can buy a hand share certificate at IPO price when corporation's market price is below IPO price
  3. Non-share/president certificates still use company.value

This prevents regression of the price calculation logic.

return company.value unless %i[share president].include?(company.type)

share = company.treasury
par = share.corporation.par_price
return company.value unless par

(par.price * share.num_shares(ceil: false)).ceil
end

def can_buy_from_ipo?(entity, company)
return false if @game.round_counter == 1
return false if @round.bought_from_market
Expand Down
Loading