lib/engine/tile.rb
# returns hash where keys are cities, and values are the edge the city or
# town should be rendered at
#
# "ct" for "city or town"
returns hash where keys are cities, and values are the edge the city or
town should be rendered at

"ct" for "city or town"
returns hash where keys are cities and values are the edge the city or town should be rendered at " ct " for " city or town "
def preferred_city_town_edges
      @preferred_city_town_edges ||=
        begin
          ct_edges = Hash.new { |h, k| h[k] = [] }
          edge_count = Hash.new(0)
          edge_count[0] += 0.1
          paths.each do |path|
            next unless (ct = path.city || path.town)
            path.exits.each do |edge|
              ct_edges[ct] << edge
              edge_count[edge] += 1
              edge_count[(edge + 1) % 6] += 0.1
              edge_count[(edge - 1) % 6] += 0.1
            end
          end
          sorted = ct_edges.each { |_, e| e.sort! }.sort_by { |_, e| e }
          sorted.map do |ct, edges_|
            edge = edges_.min_by { |e| edge_count[e] }
            edge_count[edge] += 1
            edge_count[(edge + 1) % 6] += 0.1
            edge_count[(edge - 1) % 6] += 0.1
            [ct, edge]
          end.to_h
        end
    end
def preferred_city_town_edges @preferred_city_town_edges ||= begin ct_edges = Hash . new { | h , k | h [ k ] = [ ] } edge_count = Hash . new ( 0 ) edge_count [ 0 ] += 0.1 paths . each do | path | next unless ( ct = path . city || path . town ) path . exits . each do | edge | ct_edges [ ct ] << edge edge_count [ edge ] += 1 edge_count [ ( edge + 1 ) % 6 ] += 0.1 edge_count [ ( edge - 1 ) % 6 ] += 0.1 end end sorted = ct_edges . each { | _ , e | e . sort! } . sort_by { | _ , e | e } sorted . map do | ct , edges_ | edge = edges_ . min_by { | e | edge_count [ e ] } edge_count [ edge ] += 1 edge_count [ ( edge + 1 ) % 6 ] += 0.1 edge_count [ ( edge - 1 ) % 6 ] += 0.1 [ ct , edge ] end . to_h end end
returns hash where keys are cities, and values are the edge the city or
town should be rendered at
returns hash where keys are cities and values are the edge the city or town should be rendered at
# cache per rotation # ct => nums of edges it is connected to # edge => how many tracks/cts are on that edge, plus 0.1 # for each track/ct on neighboring edges # slightly prefer to keep room along bottom to render location name # populate ct_edges and edge_count as described in above comments # sort ct_edges so that the lowest edge with any paths will be # handled first # construct the final hash to return, updating edge_count along the # way # since this edge is being used, increase its count (and that of its # neighbors) to influence what edges will be used for the remaining # cts