Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18Uruguay] Also add FCE shares to secondary corps #11209

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions lib/engine/game/g_18_uruguay/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ def next_round!
when 1
start_merge(current_entity.owner)
when 2
acquire_shares
decrease_stock_value
retreive_home_tokens
close_companies
Expand Down
35 changes: 22 additions & 13 deletions lib/engine/game/g_18_uruguay/nationalization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ def affected_shares(entity, corps)
affected
end

def find_president(holders, corps)
def find_president(holders, corps, secondary_corps)
president_candidate = nil
candidate_sum = 0
holders.each do |holder|
entity_shares = affected_shares(holder, corps)
sum = entity_shares.sum(&:percent)
sum = (entity_shares.sum(&:percent) / 20).to_i * 10
sum = secondary_corps.reduce(sum) do |second_sum, secondary_corp|
second_sum + (secondary_corp.president?(holder) ? 10 : 0)
end
if sum > candidate_sum
president_candidate = holder
candidate_sum = sum
Expand All @@ -52,18 +55,22 @@ def transfer_pres_share(corporation, owner)
corporation.owner = owner
end

def acquire_shares_in_fce(corp_fce, merge_data)
new_president = find_president(merge_data[:holders], merge_data[:corps])
transfer_pres_share(corp_fce, new_president)
def acquire_shares
ollybh marked this conversation as resolved.
Show resolved Hide resolved
new_president = find_president(@merge_data[:holders], @merge_data[:corps], @merge_data[:secondary_corps])
transfer_pres_share(@fce, new_president)

merge_data[:holders].each do |holder|
@merge_data[:holders].each do |holder|
aquired = 0
aquired = 20 if holder == new_president
entity_shares = affected_shares(holder, merge_data[:corps])
entity_shares = affected_shares(holder, @merge_data[:corps])

total_percent = entity_shares.sum(&:percent)
aquire_percent = (total_percent / 20).to_i * 10
aquire_percent = @merge_data[:secondary_corps].reduce(aquire_percent) do |sum, secondary_corps|
sum + (secondary_corps.president?(holder) ? 10 : 0)
end
while aquired < aquire_percent
share = corp_fce.shares.first
share = @fce.shares.first
aquired += share.percent
transfer_share(share, holder)
end
Expand All @@ -72,11 +79,11 @@ def acquire_shares_in_fce(corp_fce, merge_data)
odd_share = aquired * 2 != total_percent
next unless odd_share

price = corp_fce.share_price.price / 2
price = @fce.share_price.price / 2
@bank.spend(price, holder)
@log << "#{holder.name} receives #{price} from half share"
end
@log << "#{new_president.name} becomes new president of #{corp_fce.name}"
@log << "#{new_president.name} becomes new president of #{@fce.name}"
end

def compute_merger_share_price(corps)
Expand Down Expand Up @@ -134,12 +141,13 @@ def start_merge(originatior)
candidates = corps_to_nationalize
corps = candidates.take(2)
@merge_data = {
holders: share_holder_list(originatior, corps),
holders: share_holder_list(originatior, candidates),
corps: corps,
secondary_corps: [],
home_tokens: [],
tokens: [],
candidates: candidates,
corp_share_sum: 0,
}

if corps.empty?
Expand All @@ -153,8 +161,9 @@ def start_merge(originatior)
@fce.floatable = true
@stock_market.set_par(@fce, fce_share_price)
after_par(@fce)

acquire_shares_in_fce(@fce, @merge_data)
@merge_data[:corp_share_sum] = @merge_data[:holders].reduce(0) do |sum, holder|
sum + ((affected_shares(holder, @merge_data[:corps]).sum(&:percent) / 20).to_i * 10)
end
Comment on lines +126 to +128
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you need to use reduce here? Would sum be simpler?

Suggested change
@merge_data[:corp_share_sum] = @merge_data[:holders].reduce(0) do |sum, holder|
sum + ((affected_shares(holder, @merge_data[:corps]).sum(&:percent) / 20).to_i * 10)
end
@merge_data[:corp_share_sum] = @merge_data[:holders].sum do |holder|
(affected_shares(holder, @merge_data[:corps]).sum(&:percent) / 20).to_i * 10
end

end

def nationalization_final_export!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def actions(entity)
return [] if @game.merge_data[:corps].include?(entity)
return [] unless entity.loans.size.positive?
return [] if @game.maximum_loans(entity) < entity.loans.size
return [] if @game.merge_data[:corp_share_sum] + (10 * @game.merge_data[:secondary_corps].size) >= 100

actions = []
actions << 'choose'
Expand Down
Loading