Expand description
§Overview
This module solves the problem of finding the set of routes that can be run by a company to yield the highest possible revenue.
For example, the following function can find the best routes on a map for
a specific company (identified here by their Token) that owns one or
more trains, given (game-specific) rules about which
elements may be reused by a single route (conflict_rule) and which
elements may be shared by multiple routes (route_conflict_rule):
use n18route::{paths_for_token, Bonus, Criteria, ConflictRule, Trains, Routes};
use n18map::Map;
use n18token::Token;
fn find_best_routes(map: &Map, token: Token, trains: Trains,
bonuses: Vec<Bonus>) -> Routes {
// Find all of the paths that the trains could operate.
let criteria = Criteria {
token,
path_limit: trains.path_limit(),
// NOTE: game-specific rule.
conflict_rule: ConflictRule::TrackOrCityHex,
// NOTE: game-specific rule.
route_conflict_rule: ConflictRule::TrackOnly,
};
let paths = paths_for_token(&map, &criteria);
// Return the best routes out of the available paths.
trains
.select_routes(paths, bonuses)
.expect("Could not find an optimal set of routes")
}See the route-finding documentation for details.
Modules§
- bonus
- Route bonuses that can increase revenue.
- builder
- Provide a convenient way to construct arbitrary paths.
- comb
- Generate combinations of, e.g., paths for trains to operate.
- conflict
- Paths and routes may not share certain features.
- doc
- Explains how we find the best set of routes.
- path
- Overview
- perm
- Generate permutations of, e.g., trains to allocate to paths.
- search
- Search a map for paths from a starting location.
- train
- Train types and revenue earned for operating routes.
Structs§
- Criteria
- The search criteria for identifying valid paths.
- Path
- A path that a train may travel along.
- Query
- The search criteria for identifying valid paths that start from a specific location.
- Route
- A route operated by a train.
- Routes
- Pairings of trains to routes.
- Step
- A single step in a path.
- Train
- The types of trains that can operate routes to earn revenue.
- Train
Route - A train that operates a path to earn revenue.
- Trains
- The trains owned by a single company, which may operate routes.
- Visit
- A location on a path that, if the train stops here, may earn revenue.
Enums§
- Bonus
- The different types of route bonus that may be applied.
- Conflict
- A specific element of a path or route that cannot be shared.
- Conflict
Rule - A rule defines which elements of a path or route may not be shared.
- Path
Limit - Stop
Location - The different locations at which a train may stop and earn revenue.
- Train
Type - The types of trains that can operate routes to earn revenue.
Functions§
- paths_
for_ token - Returns all valid paths that match the provided criteria and which pass through any matching token on the map.