BitBully 0.0.56-a6
Loading...
Searching...
No Matches
bitbully.gui_c4.GuiC4 Class Reference

Public Member Functions

None __init__ (self)
AppLayout get_widget (self)
None destroy (self)

Public Attributes

 m_logger = logging.getLogger(self.__class__.__name__)
dict m_png
 m_n_row
int m_n_col = 6, 7
 m_height = np.zeros(7, dtype=np.int32)
float m_board_size = 3.5
bool is_busy = False
 last_event_time = time.time()
list m_movelist = []
list m_redolist = []
bool m_gameover = False
 bitbully_agent = bitbully_core.BitBullyCore(db_path)
list ims
dict m_control_buttons = {}
 output = Output()
 m_fig = fig
 m_axs = axs
list m_insert_buttons

Static Public Attributes

widgets notify_output = widgets.Output()

Protected Member Functions

None _reset (self)
npt.NDArray[np.float64] _get_fig_size_px (self)
None _create_control_buttons (self)
None _computer_move (self)
None _create_board (self)
None _popup (self, str text)
bool _is_legal_move (self, int col)
None _insert_token (self, int col, bool reset_redo_list=True)
None _redo_move (self)
None _undo_move (self)
None _update_insert_buttons (self)
int _get_img_idx (self, int col, int row)
None _paint_token (self)
None _create_buttons (self)
HBox _create_column_labels (self)
None _on_field_click (self, mpl_backend_bases.Event event)
None _check_winner (self, bitbully_core.BoardCore board)

Detailed Description

A class which allows to create an interactive Connect-4 widget.

GuiC4 is an interactive Connect-4 graphical user interface (GUI) implemented using
Matplotlib, IPython widgets, and a backend agent from the BitBully engine. It
provides the following main features:

- Interactive Game Board: Presents a dynamic 6-row by 7-column
    Connect-4 board with clickable board cells.
- Matplotlib Integration: Utilizes Matplotlib figures
    to render high-quality game visuals directly within Jupyter notebook environments.
- User Interaction: Captures and processes mouse clicks and button events, enabling
    intuitive gameplay via either direct board interaction or button controls.
- Undo/Redo Moves: Supports undo and redo functionalities, allowing users to
    navigate through their move history during gameplay.
- Automated Agent Moves: Incorporates BitBully, a Connect-4 backend engine, enabling
    computer-generated moves and board evaluations.
- Game State Handling: Detects game-over scenarios, including win/draw conditions,
    and provides immediate user feedback through popup alerts.

Attributes:
    notify_output (widgets.Output): Output widget for notifications and popups.

Examples:
        Generally, you should this method to retreive and display the widget.

        ```pycon
        >>> %matplotlib ipympl
        >>> c4gui = GuiC4()
        >>> display(c4gui.get_widget())
        ```

Definition at line 18 of file gui_c4.py.

Constructor & Destructor Documentation

◆ __init__()

None bitbully.gui_c4.GuiC4.__init__ ( self)
Init the GuiC4 widget.

Definition at line 52 of file gui_c4.py.

Member Function Documentation

◆ _check_winner()

None bitbully.gui_c4.GuiC4._check_winner ( self,
bitbully_core.BoardCore board )
protected
Check for Win or draw.

Definition at line 481 of file gui_c4.py.

◆ _computer_move()

None bitbully.gui_c4.GuiC4._computer_move ( self)
protected

Definition at line 181 of file gui_c4.py.

◆ _create_board()

None bitbully.gui_c4.GuiC4._create_board ( self)
protected

Definition at line 190 of file gui_c4.py.

◆ _create_buttons()

None bitbully.gui_c4.GuiC4._create_buttons ( self)
protected

Definition at line 376 of file gui_c4.py.

◆ _create_column_labels()

HBox bitbully.gui_c4.GuiC4._create_column_labels ( self)
protected
Creates a row with the column labels 'a' to 'g'.

Returns:
    HBox: A row of textboxes containing the columns labels 'a' to 'g'.

Definition at line 391 of file gui_c4.py.

◆ _create_control_buttons()

None bitbully.gui_c4.GuiC4._create_control_buttons ( self)
protected

Definition at line 150 of file gui_c4.py.

◆ _get_fig_size_px()

npt.NDArray[np.float64] bitbully.gui_c4.GuiC4._get_fig_size_px ( self)
protected

Definition at line 138 of file gui_c4.py.

◆ _get_img_idx()

int bitbully.gui_c4.GuiC4._get_img_idx ( self,
int col,
int row )
protected
Translates a column and row ID into the corresponding image ID.

Args:
    col (int): column (0-6) of the considered board cell.
    row (int): row (0-5) of the considered board cell.

Returns:
    int: The corresponding image id (0-41).

Definition at line 326 of file gui_c4.py.

◆ _insert_token()

None bitbully.gui_c4.GuiC4._insert_token ( self,
int col,
bool reset_redo_list = True )
protected

Definition at line 236 of file gui_c4.py.

◆ _is_legal_move()

bool bitbully.gui_c4.GuiC4._is_legal_move ( self,
int col )
protected

Definition at line 233 of file gui_c4.py.

◆ _on_field_click()

None bitbully.gui_c4.GuiC4._on_field_click ( self,
mpl_backend_bases.Event event )
protected
Based on the column where the click was detected, insert a token.

Args:
    event (mpl_backend_bases.Event): A matplotlib mouse event.

Definition at line 416 of file gui_c4.py.

◆ _paint_token()

None bitbully.gui_c4.GuiC4._paint_token ( self)
protected

Definition at line 340 of file gui_c4.py.

◆ _popup()

None bitbully.gui_c4.GuiC4._popup ( self,
str text )
protected

Definition at line 229 of file gui_c4.py.

◆ _redo_move()

None bitbully.gui_c4.GuiC4._redo_move ( self)
protected

Definition at line 274 of file gui_c4.py.

◆ _reset()

None bitbully.gui_c4.GuiC4._reset ( self)
protected

Definition at line 125 of file gui_c4.py.

◆ _undo_move()

None bitbully.gui_c4.GuiC4._undo_move ( self)
protected

Definition at line 280 of file gui_c4.py.

◆ _update_insert_buttons()

None bitbully.gui_c4.GuiC4._update_insert_buttons ( self)
protected

Definition at line 317 of file gui_c4.py.

◆ destroy()

None bitbully.gui_c4.GuiC4.destroy ( self)
Destroy and release the acquired resources.

Definition at line 491 of file gui_c4.py.

◆ get_widget()

AppLayout bitbully.gui_c4.GuiC4.get_widget ( self)
Get the widget.

Examples:
    Generally, you should this method to retreive and display the widget.

    ```pycon
    >>> %matplotlib ipympl
    >>> c4gui = GuiC4()
    >>> display(c4gui.get_widget())
    ```

Returns:
    AppLayout: the widget.

Definition at line 428 of file gui_c4.py.

Member Data Documentation

◆ bitbully_agent

bitbully.gui_c4.GuiC4.bitbully_agent = bitbully_core.BitBullyCore(db_path)

Definition at line 123 of file gui_c4.py.

◆ ims

list bitbully.gui_c4.GuiC4.ims

Definition at line 131 of file gui_c4.py.

◆ is_busy

bool bitbully.gui_c4.GuiC4.is_busy = False

Definition at line 92 of file gui_c4.py.

◆ last_event_time

bitbully.gui_c4.GuiC4.last_event_time = time.time()

Definition at line 94 of file gui_c4.py.

◆ m_axs

bitbully.gui_c4.GuiC4.m_axs = axs

Definition at line 223 of file gui_c4.py.

◆ m_board_size

float bitbully.gui_c4.GuiC4.m_board_size = 3.5

Definition at line 90 of file gui_c4.py.

◆ m_control_buttons

dict bitbully.gui_c4.GuiC4.m_control_buttons = {}

Definition at line 151 of file gui_c4.py.

◆ m_fig

bitbully.gui_c4.GuiC4.m_fig = fig

Definition at line 222 of file gui_c4.py.

◆ m_gameover

bool bitbully.gui_c4.GuiC4.m_gameover = False

Definition at line 115 of file gui_c4.py.

◆ m_height

bitbully.gui_c4.GuiC4.m_height = np.zeros(7, dtype=np.int32)

Definition at line 88 of file gui_c4.py.

◆ m_insert_buttons

bitbully.gui_c4.GuiC4.m_insert_buttons

Definition at line 241 of file gui_c4.py.

◆ m_logger

bitbully.gui_c4.GuiC4.m_logger = logging.getLogger(self.__class__.__name__)

Definition at line 55 of file gui_c4.py.

◆ m_movelist

bitbully.gui_c4.GuiC4.m_movelist = []

Definition at line 109 of file gui_c4.py.

◆ m_n_col

bitbully.gui_c4.GuiC4.m_n_col = 6, 7

Definition at line 85 of file gui_c4.py.

◆ m_n_row

bitbully.gui_c4.GuiC4.m_n_row

Definition at line 85 of file gui_c4.py.

◆ m_png

dict bitbully.gui_c4.GuiC4.m_png
Initial value:
= {
0: {"plain": png_empty, "corner": png_empty_m, "underline": png_empty_r},
1: {"plain": png_yellow, "corner": png_yellow_m},
2: {"plain": png_red, "corner": png_red_m},
}

Definition at line 79 of file gui_c4.py.

◆ m_redolist

bitbully.gui_c4.GuiC4.m_redolist = []

Definition at line 112 of file gui_c4.py.

◆ notify_output

widgets bitbully.gui_c4.GuiC4.notify_output = widgets.Output()
static

Definition at line 225 of file gui_c4.py.

◆ output

bitbully.gui_c4.GuiC4.output = Output()

Definition at line 191 of file gui_c4.py.


The documentation for this class was generated from the following file: