Reference¶
- class transcripts18xx.Game1830¶
The class to represent 1830: Railways & Robber Barons game variants.
- class transcripts18xx.Game1889¶
The class to represent Shikoku 1889 game variants.
- class transcripts18xx.Game18xx¶
Base class to define game steps, i.e. how the lines of a transcript shall be parsed. By default, checks all available pattern matcher against the line.
- companies¶
The companies available in the game.
- privates¶
The privates and their values.
- trains¶
The available trains.
- initial_round¶
The name of the initial round. Most games start with an auction round named ISR 1.
- start_capital¶
The start capital depending on the number of players.
- currency¶
The currency used in the 18xx game variant.
- class transcripts18xx.Games(value)¶
Enum class to describe the implemented games. Naming convention is an uppercase G prepended before the actual game name, e.g., G1830, G1882.
- G1830 = 0¶
- G1889 = 1¶
- static argparse(game)¶
Maps the game name to its enum member.
- Parameters:
game (
str) – The enum member name as string.- Returns:
The enum member matching to the string.
- Raises:
ValueError – If game is not found in the enum.
- game()¶
Retrieves the game name of the game.
- Returns:
Stripped G from game.
- class transcripts18xx.StepType(value)¶
Enum class to describe a step by a type. The members below depict the different actions that are available and events that occur during the game.
- AllPrivatesClose = 32¶
- BankBroke = 25¶
- Bid = 6¶
- BuyPrivate = 10¶
- BuyTrain = 13¶
- Collect = 9¶
- CompanyFloats = 20¶
- ConfirmedConsent = 39¶
- Contribute = 17¶
- DateEntry = 41¶
- DiscardTrain = 15¶
- DoesNotRun = 22¶
- ExchangePrivate = 38¶
- ExchangeTrain = 16¶
- GameEndedManually = 37¶
- GameOver = 26¶
- LayTile = 11¶
- MasterMode = 40¶
- MinimumBidDecreased = 42¶
- NewPhase = 24¶
- OperatesCompany = 31¶
- OperatingRound = 27¶
- Par = 5¶
- Pass = 7¶
- PayOut = 0¶
- PlaceToken = 12¶
- PlayerGoesBankrupt = 36¶
- PresidentNomination = 29¶
- PriorityDeal = 30¶
- PrivateAuctioned = 34¶
- PrivateCloses = 33¶
- ReceiveFunds = 19¶
- RunTrain = 14¶
- SelectsHome = 21¶
- Skip = 8¶
- StockRound = 28¶
- TrainsRust = 35¶
- Withhold = 1¶
- class transcripts18xx.TranscriptContext(raw, meta_path, result_path, game_id, game_type, valid, parse_result, verification_result, num_players, game_ending, winner, unprocessed_lines)¶
TranscriptsContext
Class implements a context to access relevant data from a parsed transcript.
- static from_raw(transcript)¶
Create a context from the raw transcript path.
- Parameters:
transcript (
Path) – The raw transcript path.- Return type:
- Returns:
Its context with relevant data.
-
game_ending:
str|None¶
-
game_id:
int¶
-
game_type:
str¶
-
meta_path:
Path¶
- metadata()¶
Load metadata of the transcript.
- Return type:
dict- Returns:
The metadata of the transcript.
-
num_players:
int|None¶
-
parse_result:
str¶
-
raw:
Path¶
- result()¶
Load parsed result of the transcript.
- Return type:
DataFrame- Returns:
The parsed result of the transcript.
-
result_path:
Path¶
-
unprocessed_lines:
list[str]¶
-
valid:
bool¶
-
verification_result:
bool|None¶
-
winner:
str|None¶
- class transcripts18xx.TranscriptParser(transcript, game)¶
Class to run the parsing pipeline. Verifies the final values of the players with the result in the game log in case the game was finished. Parsed transcript and its metadata are saved in the raw transcript folder.
- Parameters:
transcript (
Path) – The filepath to the transcript.game (
Game18xx) – The underlying 18xx game, see games.G18xx.
- parse()¶
Parses the transcript to a pandas Dataframe.
During the parsing, the metadata will be written and saved together with the parsed transcript in the root folder of the raw transcript. Further, the game state results will be verified to the result of the transcript.
- Return type:
dict- Returns:
The metadata of the parse result.
- Raises:
FileNotFoundError – If transcript does not exist.
- transcripts18xx.full_verification(transcript)¶
Run verification of the final state based on a ground truth file.
It assumes that the ground truth file is saved in the same directory as the raw transcript, with _truth.json appended to the filename. E.g 1830_123456_truth.json.
Requires the raw transcript to be parsed and the metadata to be written. Extracts the final state from the metadata and prints the differences to the console.
- Parameters:
transcript (
Path) – The raw game transcript path.- Return type:
bool- Returns:
Success of the full verification.
- Raises:
FileNotFoundError – If ground truth file was not found.