pooltool.ruleset¶
Ruleset logic
Classes¶
- class AIPlayer(*args, **kwargs)[source]¶
Base Classes:
ProtocolMethods:
- class Ruleset(players: list[Player] | None = None)[source]¶
Abstract base class for a pool game ruleset.
This class defines the skeleton of a pool game ruleset, including player management, score tracking, and shot handling. Subclasses must implement the abstract methods to specify the behavior for specific games. For examples, see currently implemented games.
- property last_player: Player¶
Returns the last player who played before the active player
If no turns have occurred, meaning the active player is the first player to shoot in the game, this erroneously returns the last player in the player order.
- Return type:
Base Classes:
Methods:
- set_next_player() None[source]¶
Sets the index for the next player
It is through this index that self.last_player and self.active_player are defined from.
- player_order() Generator[Player, None, None][source]¶
Generates player order from current player until last-to-play
- process_shot(shot: System) None[source]¶
Processes the information of the shot just played
- Parameters:
shot : System
The shot data from the system.
- advance(shot: System) None[source]¶
Advances the game state after a shot has been made and processed
- Parameters:
shot : System
The shot data from the system.
- abstract build_shot_info(shot: System) ShotInfo[source]¶
Construct the ShotInfo object for the current shot
This method evaluates the legality of a shot, determines if the turn or game is over, and if applicable, decides the winner.
- abstract next_shot_constraints(shot: System) ShotConstraints[source]¶
Determine the constraints for the next shot based on the current game state.
The method sets the conditions under which the next shot will be played, such as whether ball-in-hand rules apply and which balls are legally hittable.
- Parameters:
shot : System
The current shot being played.
- Returns:
Shot constraints for the next shot.
- Return type:
- abstract initial_shot_constraints() ShotConstraints[source]¶
Define the initial constraints for the first shot of the game.
- Returns:
Predefined shot constraints for the initial shot.
- Return type:
- class ShotConstraints(ball_in_hand: BallInHandOptions, movable: list[str] | None, cueable: list[str] | None, hittable: tuple[str, ...], call_shot: bool, ball_call: str | None = None, pocket_call: str | None = None)[source]¶
Constraints for a player’s upcoming shot
Attributes:
- ball_in_hand : BallInHandOptions¶
Enum specifying if and how the player can place the cue ball by hand.
- movable : list[str] | None¶
A list of identifiers for balls that the player is allowed to move before the shot. If None, all balls are considered movable.
- cueable : list[str] | None¶
A list of identifiers for balls that can be struck by the cue ball during the shot. If None, all balls are considered cueable.
- hittable : tuple[str, ...]¶
A tuple of identifiers for balls that must be hit for the shot to be considered legal.
- call_shot : bool¶
A boolean indicating whether the shot must be called (i.e., the player must declare which ball they intend to pocket and in which pocket). If False, ball_call and pocket_call need not be defined.
- ball_call : str | None¶
The identifier of the ball the player has called to be pocketed. If None, no specific ball has been called.
- pocket_call : str | None¶
The identifier of the pocket the player has called for the ball to be pocketed in. If None, no specific pocket has been called.
Methods:
Functions¶
- get_ball_ids_on_table(shot: System, at_start: bool, exclude: set[str] | None = None) set[str][source]¶
- get_highest_ball(shot: System, at_start: bool) Ball[source]¶
Get the highest ball on the table at start or end of shot
- get_lowest_ball(shot: System, when: StateProbe) Ball[source]¶
Get the lowest ball on the table at start or end of shot
- Parameters:
at_start
If True, the lowest ball on the table at t=0 is calculated. If False, the lowest ball at the end of the shot (t=inf) is calculated. The latter returns a different result if the lowest ball on the table was pocketed
- Return type:
- get_pocketed_ball_ids(shot: System) list[str][source]¶
Get list of ball IDs that are in the pocketed state (by end of shot)
See also get_pocketed_ball_ids_during_shot
- get_pocketed_ball_ids_during_shot(shot: System, exclude: set[str] | None = None) list[str][source]¶
Get list of ball IDs pocketed during the shot
See also get_pocketed_ball_ids
- is_shot_called_if_required(shot_constraints: ShotConstraints) bool[source]¶
- Return type:
- is_target_group_hit_first(shot: System, target_balls: tuple[str, ...], cue: str) bool[source]¶
- Return type:
- respot(shot: System, ball_id: str, x: float, y: float, z: float | None = None) None[source]¶
Respot a ball
Notes
FIXME check if respot position overlaps with ball