gui
gui.abstract_gui module
- class texasholdem.gui.abstract_gui.AbstractGUI(game=None, visible_players=None, enable_animation=True, no_wait=False)[source]
This class provides a recommended outline of the methods that every TexasHoldEm GUI should implement. It also comes with a few convenience methods for implementations, including
run_step()which runs a complete step of the game (display state, take input, show state, etc.) andreplay_history()which allows the user to step through the given history.- Parameters:
game (TexasHoldEm, optional) – The game object to attach to, all methods will default to this game. (Not necessary if only showing the history)
visible_players (Iterable[int], optional) – The players whose cards should be displayed whenever the
display_state()method is called, defaults to every player.enable_animation (bool) – If set to True, will play animations, default True.
no_wait (bool) – If set to True, disables waiting mechanisms and will not block.
- game
The game object to attach to, all methods will default to this game. (Not necessary if only showing the history)
- Type:
TexasHoldEm, optional
- visible_players
The players whose cards should be displayed whenever the
display_state()method is called, defaults to every player.- Type:
list[int], optional
- enable_animation
If set to True, will play animations, default True.
- Type:
bool
- no_wait
If set to True, disables waiting mechanisms and will not block.
- Type:
bool
- accept_input()[source]
Receive input from the user and translate the given input to the canonical (ActionType, int) tuple form.
Implementations should only focus on this direct translation and not worry about validating the move with respect to the game. Implementations should also raise a ValueError if the given user input is malformed.
- Returns:
The action
- Return type:
Tuple[ActionType, Optional[int]]
- Raises:
ValueError – If the given input could not be parsed
Added in version 0.7.0.
- display_error(error)[source]
Display any potential errors from users (malformed input, invalid action, etc.)
- Parameters:
error (str) – The error message
Added in version 0.7.0.
- display_win()[source]
Display the winners of the hand, (and everyone’s cards that didn’t fold)
Added in version 0.7.0.
- replay_history(path)[source]
Replays the given history, going forward when prompted.
This is included as a convenience method built from the other necessary abstract methods.
Added in version 0.7.0.
- run_step()[source]
Runs a complete GUI step of the hand:
Display the game state
Prompt for action from the user until valid
Take the action and display it
Display the winners if the hand ended
This is included as a convenience method built from the other necessary abstract methods.
Added in version 0.7.0.
- set_visible_players(visible_players)[source]
Make the given players’ cards visible.
- Parameters:
visible_players (Iterable[int]) – The players whose cards should be visible when the
display_state()method is called.- Raises:
ValueError – If any of the player ids given are invalid.
Added in version 0.7.0.
gui.text_gui module
- class texasholdem.gui.text_gui.TextGUI(*args, **kwargs)[source]
Bases:
AbstractGUIText-based GUI. Play Texas Hold ‘Em on the command line.
- Parameters:
game (TexasHoldEm, optional) – The game object to attach to, all methods will default to this game. (Not necessary if only showing the history)
visible_players (Iterable[int], optional) – The players whose cards should be displayed whenever the
display_state()method is called, defaults to every player.enable_animation (bool) – If set to True, will play animations, default True.
no_wait (bool) – If set to True, disables waiting mechanisms and will not block.
- game
The game object to attach to, all methods will default to this game. (Not necessary if only showing the history)
- Type:
TexasHoldEm, optional
- visible_players
The players whose cards should be displayed whenever the
display_state()method is called, defaults to every player.- Type:
Iterable[int], optional
- enable_animation
If set to True, will play animations, default True.
- Type:
bool
- no_wait
If set to True, disables waiting mechanisms and will not block.
- Type:
bool
- accept_input()[source]
Receive input from the user and translate the given input to the canonical (ActionType, int) tuple form.
Implementations should only focus on this direct translation and not worry about validating the move with respect to the game. Implementations should also raise a ValueError if the given user input is malformed.
- Returns:
The action
- Return type:
Tuple[ActionType, Optional[int]]
- Raises:
ValueError – If the given input could not be parsed
Added in version 0.7.0.
- display_error(error)[source]
Display any potential errors from users (malformed input, invalid action, etc.)
- Parameters:
error (str) – The error message
Added in version 0.7.0.
- display_win()[source]
Display the winners of the hand, (and everyone’s cards that didn’t fold)
Added in version 0.7.0.
- print_action(id, action, val=None)[source]
Display the most recent action
Deprecated since version 0.7.0: Use the
display_action()method instead. This function will be removed in version 1.0.0.
- print_state(poker_game)[source]
Display the state of the game.
Deprecated since version 0.7.0: Use the
display_state()method instead. This function will be removed in version 1.0.0.
- set_player_ids(ids)[source]
Make the given players’ cards visible.
- Parameters:
ids (Iterable[int]) – The players whose cards should be visible when the
display_state()method is called.
Deprecated since version 0.7.0: Use the
set_visible_players()method instead. This function will be removed in version 1.0.0.