Skip to content

Instantly share code, notes, and snippets.

@martindevans
Last active December 15, 2015 18:38
Show Gist options
  • Save martindevans/5304800 to your computer and use it in GitHub Desktop.
Save martindevans/5304800 to your computer and use it in GitHub Desktop.
var newRoutes = Stars
.SelectMany(sink => Stars
.Where(s => Distance(s, sink) < DISTANCE_THRESHOLD) //Eliminate stars too far away
.Where(s => s.Desirability < sink.Desirability) //Ignore routes along a negative profitability gradient
.Where(s => !IsThereARouteAlreadyBetween(sink, s)) //Don't reconsider routes which already exist
.Where(s => RandomFloat(0, 1) > SomeValue) //Arbitrarily eliminate half the routes
.Select(source => new { Source = source, Sink = sink })
)
.Select(route => new { route.Source, route.Sink, Path = Pathfind(route.Source, route.Sink) } //We can precompute paths from every star to every other star, making this quite cheap
.Select(route => new { DeltaDesirability = route.Sink.Desirability - route.Source.Desirability, route.Source, route.Sink. route.Path })
.Select(route => new { Profitability = route.DeltaDesirability / route.Path.TraversalTime, route.DeltaDesirability, route.Source, route.Sink. route.Path }) //We could use a different profit function (e.g. incorporating trade bonuses offered by the player)
.Where(route => route.Profitability > PROFITABILITY_THRESHOLD)
.OrderBy(route => route.Profitability)
.Take(ROUTE_CREATION_COUNT);
foreach (var route in routes)
{
if (route.IsProfitable)
route.Heuristic++;
else
{
route.Heuristic >> 1;
if (route.Heuristic == 0)
route.Destroy();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment