Skip to content

Commit

Permalink
Merge pull request #7223 from roseundy/connections
Browse files Browse the repository at this point in the history
Allow find_pairwise_chain to use saved_nodes even with tile upgrade
  • Loading branch information
tobymao authored Feb 18, 2022
2 parents 1d81518 + 862d4b0 commit c91aa66
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/engine/action/run_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def args_to_h
'subsidy' => route.subsidy,
'halts' => route.halts,
'abilities' => route.abilities,
'nodes' => route.nodes.map(&:full_id),
'nodes' => route.nodes.map(&:signature),
}.select { |_, v| v }
end

Expand Down
2 changes: 1 addition & 1 deletion lib/engine/operating_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(runs, dividend, revenue, laid_hexes, dividend_kind: nil)
# Convert the route into connection hexes as upgrades may break the representation
@routes = runs.to_h { |run| [run.train, run.connection_hexes] }
@halts = runs.to_h { |run| [run.train, run.halts] }
@nodes = runs.to_h { |run| [run.train, run.nodes.map(&:full_id)] }
@nodes = runs.to_h { |run| [run.train, run.nodes.map(&:signature)] }
@revenue = revenue
@dividend = dividend
@laid_hexes = laid_hexes
Expand Down
4 changes: 2 additions & 2 deletions lib/engine/part/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def id
@id ||= "#{tile.id}-#{index}"
end

def full_id
"#{hex&.id}-#{tile.name}-#{index}"
def signature
"#{hex&.id}-#{index}"
end

def hex
Expand Down
6 changes: 3 additions & 3 deletions lib/engine/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize(game, phase, train, **opts)
@subsidy = opts[:subsidy]
@halts = opts[:halts]
@abilities = opts[:abilities]
@saved_nodes = opts[:nodes] # node.full_id for every node in the route
@saved_nodes = opts[:nodes] # node.signature for every node in the route
@local_length = @game.local_length

@node_chains = {}
Expand All @@ -34,6 +34,7 @@ def initialize(game, phase, train, **opts)

def clear_cache!(all: false, only_routes: false)
@connection_hexes = nil if all
@saved_nodes = nil if all
@revenue = nil
@revenue_str = nil

Expand All @@ -47,7 +48,6 @@ def clear_cache!(all: false, only_routes: false)
@paths = nil
@stops = nil
@subsidy = nil
@saved_nodes = nil
@visited_stops = nil
@check_connected = nil
@check_distance = nil
Expand Down Expand Up @@ -407,7 +407,7 @@ def find_pairwise_chain(chains_a, chains_b, other_paths)
# pass through the nodes associated with it.
if @saved_nodes
candidates.each do |a, b, left, right, middle|
return [a, b, left, right, middle] if [left, right, middle].all? { |n| @saved_nodes.include?(n.full_id) }
return [a, b, left, right, middle] if [left, right, middle].all? { |n| @saved_nodes.include?(n.signature) }
end
end

Expand Down

0 comments on commit c91aa66

Please sign in to comment.