-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11297 from ollybh/1858switzerland-robot
[1858Switzerland] Robot variant for two-players
- Loading branch information
Showing
12 changed files
with
502 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
lib/engine/game/g_1858_switzerland/step/buy_sell_par_shares.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../g_1858/step/buy_sell_par_shares' | ||
|
||
module Engine | ||
module Game | ||
module G1858Switzerland | ||
module Step | ||
class BuySellParShares < G1858::Step::BuySellParShares | ||
ROBOT_ACTIONS = %w[buy_company].freeze | ||
|
||
def actions(entity) | ||
return super unless entity == @game.robot | ||
return [] if @acted | ||
return [] unless priciest_company | ||
|
||
ROBOT_ACTIONS | ||
end | ||
|
||
def auto_actions(entity) | ||
return super unless entity == @game.robot | ||
return [] unless (company = priciest_company) | ||
|
||
[Engine::Action::BuyCompany.new(entity, company: company, price: 0)] | ||
end | ||
|
||
def process_buy_company(action) | ||
player = action.entity | ||
company = action.company | ||
owner = company.owner | ||
|
||
raise GameError, "Cannot buy #{company.name} from #{owner.name}" unless owner == @game.bank | ||
raise GameError, "Only #{@game.robot.name} can buy a private railway company." unless player == @game.robot | ||
|
||
@log << "#{player.name} acquires #{company.name} from #{owner.name}." | ||
@game.purchase_company(player, company, action.price) | ||
track_action(action, company) | ||
end | ||
|
||
private | ||
|
||
# Finds the most expensive private railway company currently | ||
# available. If there are two at the same price then the first in | ||
# company order is returned. Nil is returned if there are no | ||
# companies available. | ||
def priciest_company | ||
companies = @game.buyable_bank_owned_companies | ||
max_value = companies.map(&:value).max | ||
companies.find { |c| c.value == max_value } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.