From 15c5cacbb4261750779882bbdfc7e6bed9808943 Mon Sep 17 00:00:00 2001 From: Patrik Olesen Date: Thu, 12 Sep 2024 16:32:02 +0200 Subject: [PATCH 01/11] [18Uruguay] Also add FCE shares to secondary corps Fixes #11111 Fixes #11074 --- lib/engine/game/g_18_uruguay/game.rb | 1 + .../game/g_18_uruguay/nationalization.rb | 35 ++++++++++++------- .../step/nationalize_corporation.rb | 1 + 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/lib/engine/game/g_18_uruguay/game.rb b/lib/engine/game/g_18_uruguay/game.rb index cecd5ef96f..674de496ae 100644 --- a/lib/engine/game/g_18_uruguay/game.rb +++ b/lib/engine/game/g_18_uruguay/game.rb @@ -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 diff --git a/lib/engine/game/g_18_uruguay/nationalization.rb b/lib/engine/game/g_18_uruguay/nationalization.rb index a4b56e1e26..1c1eac3fe7 100644 --- a/lib/engine/game/g_18_uruguay/nationalization.rb +++ b/lib/engine/game/g_18_uruguay/nationalization.rb @@ -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 @@ -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 + 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 @@ -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) @@ -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? @@ -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 end def nationalization_final_export! diff --git a/lib/engine/game/g_18_uruguay/step/nationalize_corporation.rb b/lib/engine/game/g_18_uruguay/step/nationalize_corporation.rb index 57e4916daf..604b3f3f74 100644 --- a/lib/engine/game/g_18_uruguay/step/nationalize_corporation.rb +++ b/lib/engine/game/g_18_uruguay/step/nationalize_corporation.rb @@ -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' From c91d3c1248e1e9ca7f8f389aabc87f172a9cd7b9 Mon Sep 17 00:00:00 2001 From: Patrik Olesen Date: Fri, 27 Sep 2024 07:20:19 +0200 Subject: [PATCH 02/11] [18Uruguay] Simplify acquire_shares --- .../game/g_18_uruguay/nationalization.rb | 61 ++++--------------- 1 file changed, 12 insertions(+), 49 deletions(-) diff --git a/lib/engine/game/g_18_uruguay/nationalization.rb b/lib/engine/game/g_18_uruguay/nationalization.rb index 1c1eac3fe7..a4c112559e 100644 --- a/lib/engine/game/g_18_uruguay/nationalization.rb +++ b/lib/engine/game/g_18_uruguay/nationalization.rb @@ -23,67 +23,30 @@ def affected_shares(entity, corps) affected end - 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) / 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 - end - end - president_candidate - end - - def transfer_share(share, new_owner) - corp = share.corporation - corp.share_holders[share.owner] -= share.percent - corp.share_holders[new_owner] += share.percent - share.owner.shares_by_corporation[corp].delete(share) - new_owner.shares_by_corporation[corp] << share - share.owner = new_owner - end - - def transfer_pres_share(corporation, owner) - pres_share = corporation.presidents_share - transfer_share(pres_share, owner) - corporation.owner = owner - end - def acquire_shares - 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| - aquired = 0 - aquired = 20 if holder == new_president 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 = @fce.shares.first - aquired += share.percent - transfer_share(share, holder) + num_shares = (total_percent / 20).to_i + odd_share = num_shares * 20 != total_percent + from_secondary = @merge_data[:secondary_corps].reduce(0) do |sum, secondary_corps| + sum + (secondary_corps.president?(holder) ? 1 : 0) end - number = aquire_percent - @log << "#{holder.name} receives #{number}% in FCE in exchange to the nationalized shares" - odd_share = aquired * 2 != total_percent + num_shares += from_secondary + bundle = Engine::ShareBundle.new(@fce.shares.take(9)) if num_shares == 10 + bundle = Engine::ShareBundle.new(@fce.shares.reject(&:president).take(num_shares)) unless num_shares == 10 + @share_pool.transfer_shares(bundle, holder, allow_president_change: true) + number = num_shares + @log << "#{holder.name} receives #{num_shares*10}% in FCE in exchange to the nationalized shares" + next unless odd_share 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 #{@fce.name}" + @log << "#{@fce.presidents_share.owner.name} becomes new president of #{@fce.name}" end def compute_merger_share_price(corps) From e51d38fe9cc598b853cf78e59557db8267fb1ebc Mon Sep 17 00:00:00 2001 From: Patrik Olesen Date: Fri, 27 Sep 2024 07:28:39 +0200 Subject: [PATCH 03/11] [18Uruguay] Rubocop --- lib/engine/game/g_18_uruguay/nationalization.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/engine/game/g_18_uruguay/nationalization.rb b/lib/engine/game/g_18_uruguay/nationalization.rb index a4c112559e..7f489f0c91 100644 --- a/lib/engine/game/g_18_uruguay/nationalization.rb +++ b/lib/engine/game/g_18_uruguay/nationalization.rb @@ -38,7 +38,7 @@ def acquire_shares bundle = Engine::ShareBundle.new(@fce.shares.reject(&:president).take(num_shares)) unless num_shares == 10 @share_pool.transfer_shares(bundle, holder, allow_president_change: true) number = num_shares - @log << "#{holder.name} receives #{num_shares*10}% in FCE in exchange to the nationalized shares" + @log << "#{holder.name} receives #{num_shares * 10}% in FCE in exchange to the nationalized shares" next unless odd_share From 96dd9241a38c34cc6038e2a3741eacebf633f7f9 Mon Sep 17 00:00:00 2001 From: Patrik Olesen Date: Fri, 27 Sep 2024 07:54:28 +0200 Subject: [PATCH 04/11] [18Uruguay] Rubocop --- lib/engine/game/g_18_uruguay/nationalization.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/engine/game/g_18_uruguay/nationalization.rb b/lib/engine/game/g_18_uruguay/nationalization.rb index 7f489f0c91..802cd046bb 100644 --- a/lib/engine/game/g_18_uruguay/nationalization.rb +++ b/lib/engine/game/g_18_uruguay/nationalization.rb @@ -37,7 +37,6 @@ def acquire_shares bundle = Engine::ShareBundle.new(@fce.shares.take(9)) if num_shares == 10 bundle = Engine::ShareBundle.new(@fce.shares.reject(&:president).take(num_shares)) unless num_shares == 10 @share_pool.transfer_shares(bundle, holder, allow_president_change: true) - number = num_shares @log << "#{holder.name} receives #{num_shares * 10}% in FCE in exchange to the nationalized shares" next unless odd_share From 937b22fb9e8fb38ea2892a15f6f3edd1fa3caacc Mon Sep 17 00:00:00 2001 From: patrikolesen Date: Sun, 29 Dec 2024 10:44:42 +0100 Subject: [PATCH 05/11] Update lib/engine/game/g_18_uruguay/nationalization.rb Co-authored-by: Oliver Burnett-Hall --- lib/engine/game/g_18_uruguay/nationalization.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/engine/game/g_18_uruguay/nationalization.rb b/lib/engine/game/g_18_uruguay/nationalization.rb index 802cd046bb..303f964651 100644 --- a/lib/engine/game/g_18_uruguay/nationalization.rb +++ b/lib/engine/game/g_18_uruguay/nationalization.rb @@ -34,8 +34,12 @@ def acquire_shares sum + (secondary_corps.president?(holder) ? 1 : 0) end num_shares += from_secondary - bundle = Engine::ShareBundle.new(@fce.shares.take(9)) if num_shares == 10 - bundle = Engine::ShareBundle.new(@fce.shares.reject(&:president).take(num_shares)) unless num_shares == 10 + bundle = + if num_shares == 10 + Engine::ShareBundle.new(@fce.shares.take(9)) + else + Engine::ShareBundle.new(@fce.shares.reject(&:president).take(num_shares)) + end @share_pool.transfer_shares(bundle, holder, allow_president_change: true) @log << "#{holder.name} receives #{num_shares * 10}% in FCE in exchange to the nationalized shares" From b6c664bc248f32a64bd12a1763481cbb6000a0eb Mon Sep 17 00:00:00 2001 From: patrikolesen Date: Sun, 29 Dec 2024 10:45:45 +0100 Subject: [PATCH 06/11] Update lib/engine/game/g_18_uruguay/nationalization.rb Co-authored-by: Oliver Burnett-Hall --- lib/engine/game/g_18_uruguay/nationalization.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/engine/game/g_18_uruguay/nationalization.rb b/lib/engine/game/g_18_uruguay/nationalization.rb index 303f964651..6cb24219b9 100644 --- a/lib/engine/game/g_18_uruguay/nationalization.rb +++ b/lib/engine/game/g_18_uruguay/nationalization.rb @@ -127,8 +127,8 @@ def start_merge(originatior) @fce.floatable = true @stock_market.set_par(@fce, fce_share_price) after_par(@fce) - @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) + @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 From e0f148c8c6cd98a7ce6f7282a7b781518eb1bac1 Mon Sep 17 00:00:00 2001 From: patrikolesen Date: Sun, 29 Dec 2024 10:45:56 +0100 Subject: [PATCH 07/11] Update lib/engine/game/g_18_uruguay/nationalization.rb Co-authored-by: Oliver Burnett-Hall --- lib/engine/game/g_18_uruguay/nationalization.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/engine/game/g_18_uruguay/nationalization.rb b/lib/engine/game/g_18_uruguay/nationalization.rb index 6cb24219b9..e3aaa941f6 100644 --- a/lib/engine/game/g_18_uruguay/nationalization.rb +++ b/lib/engine/game/g_18_uruguay/nationalization.rb @@ -28,8 +28,7 @@ def acquire_shares entity_shares = affected_shares(holder, @merge_data[:corps]) total_percent = entity_shares.sum(&:percent) - num_shares = (total_percent / 20).to_i - odd_share = num_shares * 20 != total_percent + num_shares, odd_shares = (total_percent / 10).divmod(2) from_secondary = @merge_data[:secondary_corps].reduce(0) do |sum, secondary_corps| sum + (secondary_corps.president?(holder) ? 1 : 0) end From dfaf97b4947b9b2068e1280d5f913a20e8c452ed Mon Sep 17 00:00:00 2001 From: patrikolesen Date: Sun, 29 Dec 2024 10:46:53 +0100 Subject: [PATCH 08/11] Update lib/engine/game/g_18_uruguay/nationalization.rb Co-authored-by: Oliver Burnett-Hall --- lib/engine/game/g_18_uruguay/nationalization.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/engine/game/g_18_uruguay/nationalization.rb b/lib/engine/game/g_18_uruguay/nationalization.rb index e3aaa941f6..09f127b6c1 100644 --- a/lib/engine/game/g_18_uruguay/nationalization.rb +++ b/lib/engine/game/g_18_uruguay/nationalization.rb @@ -29,9 +29,7 @@ def acquire_shares total_percent = entity_shares.sum(&:percent) num_shares, odd_shares = (total_percent / 10).divmod(2) - from_secondary = @merge_data[:secondary_corps].reduce(0) do |sum, secondary_corps| - sum + (secondary_corps.president?(holder) ? 1 : 0) - end + from_secondary = @merge_data[:secondary_corps].count { |corp| corp.president?(holder) } num_shares += from_secondary bundle = if num_shares == 10 From 3dbe15a70bc008f57267d584261d1927fbe7edb3 Mon Sep 17 00:00:00 2001 From: Patrik Olesen Date: Sun, 29 Dec 2024 11:49:06 +0100 Subject: [PATCH 09/11] Rubucop --- lib/engine/game/g_18_uruguay/nationalization.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/engine/game/g_18_uruguay/nationalization.rb b/lib/engine/game/g_18_uruguay/nationalization.rb index 09f127b6c1..1fb4860958 100644 --- a/lib/engine/game/g_18_uruguay/nationalization.rb +++ b/lib/engine/game/g_18_uruguay/nationalization.rb @@ -28,10 +28,13 @@ def acquire_shares entity_shares = affected_shares(holder, @merge_data[:corps]) total_percent = entity_shares.sum(&:percent) - num_shares, odd_shares = (total_percent / 10).divmod(2) - from_secondary = @merge_data[:secondary_corps].count { |corp| corp.president?(holder) } + num_shares = (total_percent / 20).to_i + odd_share = num_shares * 20 != total_percent + from_secondary = @merge_data[:secondary_corps].reduce(0) do |sum, secondary_corps| + sum + (secondary_corps.president?(holder) ? 1 : 0) + end num_shares += from_secondary - bundle = + bundle = if num_shares == 10 Engine::ShareBundle.new(@fce.shares.take(9)) else From 76d545c9df12d0b2a58c264bd53fb6a80c86cbaf Mon Sep 17 00:00:00 2001 From: Patrik Olesen Date: Thu, 9 Jan 2025 21:12:02 +0100 Subject: [PATCH 10/11] Revert "Rubucop" This reverts commit 3dbe15a70bc008f57267d584261d1927fbe7edb3. --- lib/engine/game/g_18_uruguay/nationalization.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/engine/game/g_18_uruguay/nationalization.rb b/lib/engine/game/g_18_uruguay/nationalization.rb index 1fb4860958..09f127b6c1 100644 --- a/lib/engine/game/g_18_uruguay/nationalization.rb +++ b/lib/engine/game/g_18_uruguay/nationalization.rb @@ -28,13 +28,10 @@ def acquire_shares entity_shares = affected_shares(holder, @merge_data[:corps]) total_percent = entity_shares.sum(&:percent) - num_shares = (total_percent / 20).to_i - odd_share = num_shares * 20 != total_percent - from_secondary = @merge_data[:secondary_corps].reduce(0) do |sum, secondary_corps| - sum + (secondary_corps.president?(holder) ? 1 : 0) - end + num_shares, odd_shares = (total_percent / 10).divmod(2) + from_secondary = @merge_data[:secondary_corps].count { |corp| corp.president?(holder) } num_shares += from_secondary - bundle = + bundle = if num_shares == 10 Engine::ShareBundle.new(@fce.shares.take(9)) else From dabb383a17b1f68628ecfdb2c608fe4c6ce872e8 Mon Sep 17 00:00:00 2001 From: Patrik Olesen Date: Thu, 9 Jan 2025 21:18:20 +0100 Subject: [PATCH 11/11] [18Uruguay] Adding correct rubocop commit --- lib/engine/game/g_18_uruguay/nationalization.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/engine/game/g_18_uruguay/nationalization.rb b/lib/engine/game/g_18_uruguay/nationalization.rb index 09f127b6c1..02f56d9651 100644 --- a/lib/engine/game/g_18_uruguay/nationalization.rb +++ b/lib/engine/game/g_18_uruguay/nationalization.rb @@ -31,7 +31,7 @@ def acquire_shares num_shares, odd_shares = (total_percent / 10).divmod(2) from_secondary = @merge_data[:secondary_corps].count { |corp| corp.president?(holder) } num_shares += from_secondary - bundle = + bundle = if num_shares == 10 Engine::ShareBundle.new(@fce.shares.take(9)) else @@ -40,7 +40,7 @@ def acquire_shares @share_pool.transfer_shares(bundle, holder, allow_president_change: true) @log << "#{holder.name} receives #{num_shares * 10}% in FCE in exchange to the nationalized shares" - next unless odd_share + next unless odd_shares price = @fce.share_price.price / 2 @bank.spend(price, holder)