lib/engine/game/g_1862/game.rb
# given a set of routes that connect end-to-end
# find the start and stop
given a set of routes that connect end-to-end
find the start and stop
given a set of routes that connect end - to - end find the start and stop
def freight_set_ends(set)
          ends = []
          nodes = Hash.new { |h, k| h[k] = [] }
          set.each do |r|
            visits = r.visited_stops
            nodes[visits.first] << r
            nodes[visits.last] << r
          end
          nodes.keys.each { |n| ends << n if nodes[n].one? }
          raise GameError, 'Logic error: freight set with only one end' if ends.one?
          ends = [nodes.keys.first, nodes.keys.first] if ends.empty?
          ends
        end
def freight_set_ends ( set ) ends = [ ] nodes = Hash . new { | h , k | h [ k ] = [ ] } set . each do | r | visits = r . visited_stops nodes [ visits . first ] << r nodes [ visits . last ] << r end nodes . keys . each { | n | ends << n if nodes [ n ] . one? } raise GameError , 'Logic error: freight set with only one end' if ends . one? ends = [ nodes . keys . first , nodes . keys . first ] if ends . empty? ends end
given a set of routes that connect end-to-end
find the start and stop
given a set of routes that connect end - to - end find the start and stop
# if no ends, we have a loop: pick first node # FIXME: pick the highest revenue node
set
<not_specific>