From a7bab07d310a5b96caddfb284090be2a9b35f3c4 Mon Sep 17 00:00:00 2001 From: Steve Undy Date: Thu, 17 Feb 2022 15:00:47 -0700 Subject: [PATCH 1/2] Allow find_pairwise_chain to use saved_nodes even with tile upgrade --- lib/engine/action/run_routes.rb | 2 +- lib/engine/operating_info.rb | 2 +- lib/engine/part/base.rb | 4 ++-- lib/engine/route.rb | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/engine/action/run_routes.rb b/lib/engine/action/run_routes.rb index dee8ae71cb..3d051c1881 100644 --- a/lib/engine/action/run_routes.rb +++ b/lib/engine/action/run_routes.rb @@ -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(&:partial_id), }.select { |_, v| v } end diff --git a/lib/engine/operating_info.rb b/lib/engine/operating_info.rb index f09e76e47d..449277acbb 100644 --- a/lib/engine/operating_info.rb +++ b/lib/engine/operating_info.rb @@ -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(&:partial_id)] } @revenue = revenue @dividend = dividend @laid_hexes = laid_hexes diff --git a/lib/engine/part/base.rb b/lib/engine/part/base.rb index b398d5f423..51800347fd 100644 --- a/lib/engine/part/base.rb +++ b/lib/engine/part/base.rb @@ -13,8 +13,8 @@ def id @id ||= "#{tile.id}-#{index}" end - def full_id - "#{hex&.id}-#{tile.name}-#{index}" + def partial_id + "#{hex&.id}-#{index}" end def hex diff --git a/lib/engine/route.rb b/lib/engine/route.rb index 15c8d144a6..e23b1b47b2 100644 --- a/lib/engine/route.rb +++ b/lib/engine/route.rb @@ -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.partial_id for every node in the route @local_length = @game.local_length @node_chains = {} @@ -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 @@ -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 @@ -88,7 +88,7 @@ def chains end def nodes - chains.flat_map { |c| c['nodes'] }.uniq.compact + chains.flat_map { |c| c[:nodes] }.uniq.compact end def next_chain(node, chain, other) @@ -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.partial_id) } end end From 862d4b07c09a42b2a2b66498c40e72928547929a Mon Sep 17 00:00:00 2001 From: Steve Undy Date: Thu, 17 Feb 2022 19:21:37 -0700 Subject: [PATCH 2/2] renamed partial_id to signature --- lib/engine/action/run_routes.rb | 2 +- lib/engine/operating_info.rb | 2 +- lib/engine/part/base.rb | 2 +- lib/engine/route.rb | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/engine/action/run_routes.rb b/lib/engine/action/run_routes.rb index 3d051c1881..24fd82c5d5 100644 --- a/lib/engine/action/run_routes.rb +++ b/lib/engine/action/run_routes.rb @@ -51,7 +51,7 @@ def args_to_h 'subsidy' => route.subsidy, 'halts' => route.halts, 'abilities' => route.abilities, - 'nodes' => route.nodes.map(&:partial_id), + 'nodes' => route.nodes.map(&:signature), }.select { |_, v| v } end diff --git a/lib/engine/operating_info.rb b/lib/engine/operating_info.rb index 449277acbb..3fa3e1661f 100644 --- a/lib/engine/operating_info.rb +++ b/lib/engine/operating_info.rb @@ -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(&:partial_id)] } + @nodes = runs.to_h { |run| [run.train, run.nodes.map(&:signature)] } @revenue = revenue @dividend = dividend @laid_hexes = laid_hexes diff --git a/lib/engine/part/base.rb b/lib/engine/part/base.rb index 51800347fd..795e083e11 100644 --- a/lib/engine/part/base.rb +++ b/lib/engine/part/base.rb @@ -13,7 +13,7 @@ def id @id ||= "#{tile.id}-#{index}" end - def partial_id + def signature "#{hex&.id}-#{index}" end diff --git a/lib/engine/route.rb b/lib/engine/route.rb index e23b1b47b2..c925a8910b 100644 --- a/lib/engine/route.rb +++ b/lib/engine/route.rb @@ -20,7 +20,7 @@ def initialize(game, phase, train, **opts) @subsidy = opts[:subsidy] @halts = opts[:halts] @abilities = opts[:abilities] - @saved_nodes = opts[:nodes] # node.partial_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 = {} @@ -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.partial_id) } + return [a, b, left, right, middle] if [left, right, middle].all? { |n| @saved_nodes.include?(n.signature) } end end