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

Conversation

patrikolesen
Copy link
Contributor

@patrikolesen patrikolesen commented Sep 12, 2024

Fixes #11111
Fixes #11074

Fixes #[PUT_ISSUE_NUMBER_HERE]

Before clicking "Create"

  • Branch is derived from the latest master
  • Add the pins or archive_alpha_games label if this change will break existing games
    This can break existing games
  • Code passes linter with docker compose exec rack rubocop -a
  • Tests pass cleanly with docker compose exec rack rake

Implementation Notes

Explanation of Change

Screenshots

Any Assumptions / Hacks

@ollybh ollybh added archive_alpha_games Needs alpha games archiving 18Uruguay labels Sep 12, 2024
Copy link
Collaborator

@ollybh ollybh left a comment

Choose a reason for hiding this comment

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

This is looking much better. I've suggested a couple more tweaks to the code, nothing major this time.

Comment on lines +37 to +38
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
Copy link
Collaborator

Choose a reason for hiding this comment

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

The if/unless modifiers are testing the same thing, so this would be clearer structured using an if/else statement.

Suggested change
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

Comment on lines +33 to 35
from_secondary = @merge_data[:secondary_corps].reduce(0) do |sum, secondary_corps|
sum + (secondary_corps.president?(holder) ? 1 : 0)
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

You're trying to find how many of the secondary corporations the player is president of, right? This might be simpler:

Suggested change
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) }

Comment on lines +31 to +32
num_shares = (total_percent / 20).to_i
odd_share = num_shares * 20 != total_percent
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
num_shares = (total_percent / 20).to_i
odd_share = num_shares * 20 != total_percent
num_shares, odd_shares = (total_percent / 10).divmod(2)

Comment on lines +126 to +128
@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
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
18Uruguay archive_alpha_games Needs alpha games archiving
Projects
None yet
2 participants