1"""Agent interface definitions for Connect-4.
3This module defines the minimal, structural interface that Connect-4 agents must
4implement in order to be compatible with the interactive GUI and other
5high-level components. The interface is expressed using ``typing.Protocol`` to
6enable static type checking without requiring inheritance or tight coupling
7between agents and consumers.
10from __future__
import annotations
12from typing
import Protocol, runtime_checkable
19 """Minimal interface a Connect-4 agent must implement to work with ``GuiC4``.
21 This interface is intentionally aligned with the public ``BitBully`` API,
22 but excludes BitBully-specific engine features such as opening-book handling,
23 node counters, transposition tables, and specialized search entry points.
26 - ``score_all_moves``: Provide integer evaluations for all *legal* moves.
27 - ``best_move``: Select one legal move using BitBully-compatible
28 tie-breaking semantics.
31 - Scores are integers where **larger values are better** for the side to move.
32 - The absolute scale is agent-defined.
33 - The GUI only relies on *relative ordering* and legality.
37 """Score all legal moves for the given board state.
41 Current Connect-4 board position.
45 Mapping ``{column: score}`` for all *legal* columns (0..6).
46 Columns that are full or illegal **must not** appear in the mapping.
49 - Higher scores indicate better moves.
50 - The returned dictionary may contain between 0 and 7 entries.
58 """Return the best legal move (column index) for the side to move.
62 Current Connect-4 board position.
66 Selected column index in the range ``0..6``.
70 def score_move(self, board: Board, column: int, first_guess: int = 0) -> int:
71 """Evaluate a single legal move for the given board state.
73 This method is optional and not required by the GUI, but can be useful
74 for agents that support fine-grained move evaluation.
78 Current Connect-4 board position.
80 Column index (0..6) of the move to evaluate.
82 Optional initial guess for iterative or search-based agents.
83 Implementations may safely ignore this parameter.
87 Evaluation score for the given move.
int score_move(self, Board board, int column, int first_guess=0)
dict[int, int] score_all_moves(self, Board board)
int best_move(self, Board board)