Skip to main content

Library for caluclating routes in 18xx train games.

Project description

A library for calculating optimal routes by railroad for each train for the 18xx family of board games.

This is intended to support most 18xx games. The common route finding rules and value calculations are hard-coded, and game specific rules are configured by a set of JSON files (distributed in the package), which setup things like the board layout and available trains. More complex game-specific rules are implemented via game-specific modules and hooks. There are almost certainly features I haven’t accounted for, as there are many 18xx games, and I haven’t played them all. Those features will be added over time, as I support more games.

The input is a set of CSV files, which form a snapshot of the game’s current state. Some basic validation is performed, such as tiles not running off the board and stations not overflowing any cities. The output is a route for each of the requested railroad’s trains, presented as both every space used, and as the list of stops (and their values) counted.

Currently supported games: 1846, 1889

Usage

calc-route <GAME> <RAILROAD> <BOARD STATE> <RAILROAD STATES> [-p <PRIVATE COMPANY STATE>]

Using the configuration files for GAME, find the best set of routes that can be run by RAILROAD, given the BOARD STATE and RAILROAD STATE (and optionally PRIVATE COMPANY STATE).

Positional

GAME is the name of the game whose configuration files should be used (e.g. 1846). This will determine the game board, available tiles and trains and railroads, as well as some game rules (such as phase names and when private companies close).

RAILROAD is the name of the railroad being run. You may use its full name, or one of its nicknames. The railroad must be listed in RAILROAD STATES (described below).

Board State

BOARD STATE is a filepath to a CSV file which contains tile coordinates and orientations. Validation is performed to confirm no tiles run off the board, or into the side of a built-in red (off-board) or gray space. No check on tile inventory is currently performed.

The format of each row is “coordinate; tile ID; orientation”. For example, D14; 15; 4. Note the use of semi-colons as column separators.

coordinate refers to the coordinate system on the board. Attempting to place a tile on an illegal space (e.g. not on the map, over a built-in gray tile, etc) will raise a ValueError. If 2 rows provide the same coordinate, they cannot indicate the same color tile. No check is performed that the older tile preserves the new one’s path.

tile ID refers to the ID number printed on the tile.

orientation is a value from 0 to 5 (inclusive). Orientation 0 matches its image on Keith Thomasson’s 18xx Tiles Database. Some tile sets on the site are displayed with a flat bottom edge. To align them with the other tiles, rotate them 30 degrees COUNTERCLOCKWISE to get orientation 0. Other orientations are determined by rotating 60 degrees CLOCKWISE from orientation 0.

Railroad States

RAILROAD STATES is the filepath to a CSV containing which railroads are “in play”. Railroads in this file have their home station automatically placed, in addition to the other specified stations.

Each row can take 2 formats. The less common (and simpler) one is “name; removed”. For example, Pennsylania Railroad; removed. In some games, home stations are treated differently whether a railroad was removed from the game (e.g. due to player counts) or if it just hasn’t floated yet. This allows that distinction to be made.

The format of each row is “name; trains; stations”. For example, Baltimore & Ohio; 4 / 6, 6; C15, D6: E5, G7. Note the use of semi-colons as column separators.

name is the full name of the railroad. This must match one of the railroads in the railroads.json file, which will be the same as in the game. Any railroad which doesn’t show up in this file is assumed to have not yet placed its home station.

trains is a comma-separated list of trains. This must match on of the trains in the trains.json file (whitespace is removed before comparison). There is no limit on the numbed of trains per railroad.

stations is a command-separated list of coordinates. These are checked to ensure they are cities, and that they have not gone over capacity. For each station in a split city (i.e. a city whose slots are not clustered), either its branch or a unqiue exit must be indicated. A branch is made up of the coorindates of each neighbor of the station slot, surrounded by square brackets and separated by spaces. A unique exit is just the coordinate of the unique exit. In the example above, Baltimore & Ohio has a station on D6 (Chicago), on the branch which runs through unqiue exit E5.

Private Company State (-p | –private-companies-file)

PRIVATE COMPANY STATE is the filepath to a CSV containing which private companies are in play. The exact interpretation will be determined by the needs of the game, and key off of the name of the private company. Note that each game is only guaranteed to implement private companies which have an impact on train routes.

Each row’s format will be “name; owner; coordinate”. For example, Steamboat Company; Grand Trunk; G19. Note that each game defines its own parser, so this format might differ between games, although the intention is to adhere to it as much as possible.

name is the name of one of the private companies in the game. If a private company does not show up in this file, it is assumed to be owned by a player.

owner is the name of the railroad which owns the private company.

coordinate is the coordinate that this private company impacts, if relevant. This will mostly be relevant for private companies which place tokens. It can be omitted for private comapnies which don’t impact the board (e.g. 1846’s Mail Contract).

Game Specific Notes

1846

All private company entries follow the standard format.

  • Steamboat Company and Meat Packing Company: validate their token is placed on a legal space, if it is placed.

  • Big 4 and Michigan Southern: ignores the coordinate argument. If omitted or an owner is not listed, and private companies have not closed, a station owned by no one is placed on their home tile. If it is owned, that station is assigned to the owning railroad.

  • Mail Contract: ignores the coordinate argument. Modifies the route value automatically.

1889

Does not validate the port tile is placed on a port space. The code cannot currently handle a space which can be upgraded to multiple different types of tiles.

No private companies impact route finding or route values. A couple do impact tile validity, but I don’t think it’s worth it.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

routes-18xx-0.5.tar.gz (29.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

routes_18xx-0.5-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

Details for the file routes-18xx-0.5.tar.gz.

File metadata

  • Download URL: routes-18xx-0.5.tar.gz
  • Upload date:
  • Size: 29.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for routes-18xx-0.5.tar.gz
Algorithm Hash digest
SHA256 738b18d283ca4877224dd1127bea27dd23ed61607327ce270f0d400239cea3fa
MD5 273b3e4c50f7e6225240050224b46eea
BLAKE2b-256 cbf8727e940642ec136fd4ea7a92d7759942b98fdc2e99dc0bdf4b9e3008625f

See more details on using hashes here.

File details

Details for the file routes_18xx-0.5-py3-none-any.whl.

File metadata

  • Download URL: routes_18xx-0.5-py3-none-any.whl
  • Upload date:
  • Size: 34.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for routes_18xx-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 95ef8e3ad7da1d6e2b251f0b6c68bfc5d5edd67502454a407b8017cb94e9f582
MD5 f2f35cc80940dbec95c4586b357f5566
BLAKE2b-256 a88ce6d5307d302c2fb59b3ddde2b416b4b6e82df2f1841e60f1f8dcefc74cf2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page