API documentation
Map machinery to represent game board.
Map
Representation of a game board.
Source code in ticket_to_ride/map.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
__init__(routes, name='Anonymous')
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the map, e.g. "North America". |
'Anonymous'
|
routes |
Iterable[Route]
|
Routes to form a map. |
required |
Source code in ticket_to_ride/map.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
__str__()
Return readable string representation of self.
Source code in ticket_to_ride/map.py
43 44 45 46 47 |
|
calculate_centrality()
Calculate centrality measure of all involved cities.
Returns:
Type | Description |
---|---|
Dict[City, float]
|
A mapping from cities to their centrality measure, sorted from high to low centrality. |
Source code in ticket_to_ride/map.py
110 111 112 113 114 115 116 117 |
|
calculate_contrast_ratio()
Calculate the contrast ratio of a map which is a fraction of neutral-colored routes.
Source code in ticket_to_ride/map.py
124 125 126 127 128 |
|
calculate_routes_by_color()
Calculate the number of routes by color and return as a mapping from color to number of routes.
Source code in ticket_to_ride/map.py
119 120 121 122 |
|
visualize(node_size=1400)
Visualize self as a graph figure similar to actual game board.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_size |
int
|
Size of nodes to display. |
1400
|
Returns:
Type | Description |
---|---|
None
|
None, just plt.show()s the map. |
Source code in ticket_to_ride/map.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
Route machinery to represent routes between cities.
Route
Bases: BaseModel
Representation of a route between cities.
Source code in ticket_to_ride/route.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
involved_cities: tp.FrozenSet[City]
property
Get cities involved in a route.
TODO: Move to post_init since value in not changed along lifecycle?
points_value: float
property
Get points value of a route.
__eq__(other)
Check if two routes are equivalent.
Source code in ticket_to_ride/route.py
39 40 41 42 43 44 45 46 47 48 49 |
|
add_as_edge(graph)
Add self as an edge on a given graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph |
Graph
|
A graph to add self as an edge on. |
required |
Returns:
Name | Type | Description |
---|---|---|
None |
None
|
Modifies the graph passed as an argument in place. |
Source code in ticket_to_ride/route.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
Ticket machinery to represent destination tickets.
Ticket
Ticket machinery to represent destination tickets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
origin |
Origin city as defined in the ticket. |
required | |
destination |
Destination city as defined in the ticket. |
required | |
face_value |
Points value specified on the ticket. |
required |
Source code in ticket_to_ride/ticket.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
objective_cities: tp.FrozenSet[City]
property
Get an unordered pair of cities which a ticket prescribes to connect.
City machinery to represent nodes of the board.
City
Bases: BaseModel
City machinery to represent nodes of the board.
Source code in ticket_to_ride/city.py
12 13 14 15 16 |
|
Functional APIs to work with various machinery across the project.
evaluate_tickets(tickets, board_map)
Evaluate tickets against a board map and get a summary table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tickets |
Iterable[Ticket]
|
Tickets to evaluate. |
required |
board_map |
Map
|
A board map to evaluate tickets against. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
A pandas DataFrame with one row representing one ticket and columns storing various statistics. |
Notes
Ticket profitability concept is inspired by the article from Rakesh Chintha: https://genielab.github.io/data-stories/ttr_analysis/#
Source code in ticket_to_ride/functional.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|