Alley Class
Represents a bowling alley where games are played, including details about the lane conditions.
| Attributes: |
|
|---|
Source code in src/virtual_lanes/alley.py
__init__(name, location, lane_type)
Initialize a new Alley instance.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Source code in src/virtual_lanes/alley.py
__str__()
Return a string representation of the Alley instance, which is helpful for debugging and logging.
| Returns: |
|
|---|
Source code in src/virtual_lanes/alley.py
Bowler Class
Represents a bowler in a bowling simulation, including probabilities for striking and sparing, as well as personal characteristics like handedness and bowling technique.
| Attributes: |
|
|---|
Source code in src/virtual_lanes/bowler.py
__init__(name, strike_prob, spare_prob, handedness='right', technique='single')
Initializes a new instance of Bowler.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Source code in src/virtual_lanes/bowler.py
__str__()
Returns a string representation of the Bowler instance.
| Returns: |
|
|---|
Source code in src/virtual_lanes/bowler.py
Scoring Class
Source code in src/virtual_lanes/scoring.py
current_frame(frames)
staticmethod
Calculate the score using current frame scoring rules, also known as World Bowling scoring.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/virtual_lanes/scoring.py
nine_pin_no_tap(frames)
staticmethod
Calculate the score for a 9-pin no-tap game, where knocking down 9 pins counts as a strike.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/virtual_lanes/scoring.py
traditional(frames)
staticmethod
Calculate the traditional bowling score from a list of frames.
Each frame should be represented by a tuple indicating the number of pins knocked down in each roll.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/virtual_lanes/scoring.py
Game Class
Manages the simulation of a bowling game, providing detailed frame-by-frame results for each bowler.
This class supports simulations on specified alleys with distinct characteristics, influencing the gameplay of the bowlers.
| Attributes: |
|---|
Source code in src/virtual_lanes/game.py
9 10 11 12 13 14 15 16 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 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 | |
__init__(bowlers, alley, random_seed=None)
Initialises a game with a list of bowlers and the alley where the game is played.
| Parameters: |
|---|
Source code in src/virtual_lanes/game.py
frame_by_frame_generator()
A generator to simulate the game frame-by-frame, yielding results for each frame for all bowlers.
| Yields: |
|
|---|
Source code in src/virtual_lanes/game.py
simulate_frame(bowler, frame_number)
Simulates a single frame for a given bowler based on the frame number.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/virtual_lanes/game.py
simulate_game()
Simulates a complete game for all bowlers, returning the frame-by-frame results.
| Returns: |
|
|---|
Source code in src/virtual_lanes/game.py
simulate_last_frame(bowler)
Simulates the 10th frame, which may include up to three rolls depending on the bowler's performance.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/virtual_lanes/game.py
simulate_regular_frame(bowler)
Simulates a regular frame (not the last one), accounting for strikes, spares and open frames.
The first ball is a strike with probability bowler.strike_prob. Otherwise, if pins
remain the bowler converts the spare with probability bowler.spare_prob; failing that
the second ball leaves an open frame.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/virtual_lanes/game.py
Tournament Class
Source code in src/virtual_lanes/tournament.py
__init__(bowlers, alley, num_games=1)
Initialize a Tournament instance with bowlers, the alley where the tournament is played, and the number of games each bowler will play.
| Parameters: |
|---|
| Attributes: |
|
|---|
Source code in src/virtual_lanes/tournament.py
get_average_scores()
Calculate and return the average scores for each bowler in the tournament.
| Returns: |
|
|---|
Source code in src/virtual_lanes/tournament.py
get_results()
Calculate and return the total scores for each bowler over the course of the tournament.
| Returns: |
|
|---|
Source code in src/virtual_lanes/tournament.py
run_tournament()
Simulate the entire tournament, running the specified number of games for each bowler.
Source code in src/virtual_lanes/tournament.py
BowlingDatabase Class
Handles the storage and retrieval of bowling simulation data in an SQLite database. Provides methods to add and manage bowlers, alleys, games, and detailed game statistics.
Source code in src/virtual_lanes/bowling_database.py
8 9 10 11 12 13 14 15 16 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 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 168 169 170 171 172 | |
__init__(db_name='bowling.db')
Initialises the database connection and creates tables if they do not already exist.
| Parameters: |
|
|---|
Source code in src/virtual_lanes/bowling_database.py
add_alley(alley)
Adds a new bowling alley to the database.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/virtual_lanes/bowling_database.py
add_bowler(bowler)
Adds a new bowler to the database or updates an existing bowler with the same name.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/virtual_lanes/bowling_database.py
add_game(date, alley_id, oil_pattern_id, bowler_id, frames)
Adds a new game along with detailed frame data to the database.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/virtual_lanes/bowling_database.py
calculate_stats(frames)
Calculate total score, strike, and spare percentages from frame data.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in src/virtual_lanes/bowling_database.py
close()
create_tables()
Creates tables in the database if they do not exist to store bowlers, alleys, games, and game details.
Source code in src/virtual_lanes/bowling_database.py
League Class
Source code in src/virtual_lanes/league.py
__init__(name, alley, oil_pattern, team_size, num_games_per_night, season_length)
Initialises a league with specified parameters, setting up the environment where the league games are played, the type of oil pattern used, the team size, the number of games per league night, and the duration of the season.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Source code in src/virtual_lanes/league.py
add_team(team)
Adds a team to the league. Ensures the team size matches the league's required team size.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Source code in src/virtual_lanes/league.py
run_season()
Simulates the entire season of the league, organising games per night for each team over the specified season length.
| Returns: |
|
|---|