Skip to content

Commit

Permalink
[18RoyalGorge] Require graph connection for cross-buying trains
Browse files Browse the repository at this point in the history
From page 13 of 24 in the [current rulebook PDF][0].

Check for the connection when processing the action--instead of when finding
available trains to buy--to minimize the necessary graph checks.

Fixes tobymao#11364

[0]: https://boardgamegeek.com/filepage/284918/graphic-rulebook-preliminary
  • Loading branch information
michaeljb committed Dec 1, 2024
1 parent e09c60d commit a9b43d7
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/engine/game/g_18_royal_gorge/step/buy_train.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ def room?(entity)
# even when train tight, there's room for a self-rust
return true if entity.trains.any? { |t| t.rusts_on == upcoming_train.name }
end

def check_connected!(buyer, train)
return if train.owner == @game.depot

seller = train.corporation
seller_nodes = @game.graph.connected_nodes(seller)
return if @game.graph.connected_nodes(buyer).any? { |node, _| seller_nodes.include?(node) }

raise GameError, "#{buyer.name} must be connected to #{seller.name} to buy their train."
end

def process_buy_train(action)
check_connected!(action.entity, action.train)
super
end
end
end
end
Expand Down

0 comments on commit a9b43d7

Please sign in to comment.