Last active
December 15, 2015 18:38
-
-
Save martindevans/5304800 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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