BitBully 0.0.74
Loading...
Searching...
No Matches
agent_interface.py
1"""Agent interface definitions for Connect-4.
2
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.
8"""
9
10from __future__ import annotations
11
12from typing import Protocol, runtime_checkable
13
14from . import Board
15
16
17@runtime_checkable
18class Connect4Agent(Protocol):
19 """Minimal interface a Connect-4 agent must implement to work with ``GuiC4``.
20
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.
24
25 Required methods:
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.
29
30 Notes on scoring:
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.
34 """
35
36 def score_all_moves(self, board: Board) -> dict[int, int]:
37 """Score all legal moves for the given board state.
38
39 Args:
40 board (Board):
41 Current Connect-4 board position.
42
43 Returns:
44 dict[int, int]:
45 Mapping ``{column: score}`` for all *legal* columns (0..6).
46 Columns that are full or illegal **must not** appear in the mapping.
47
48 Notes:
49 - Higher scores indicate better moves.
50 - The returned dictionary may contain between 0 and 7 entries.
51 """
52 ...
53
55 self,
56 board: Board,
57 ) -> int:
58 """Return the best legal move (column index) for the side to move.
59
60 Args:
61 board (Board):
62 Current Connect-4 board position.
63
64 Returns:
65 int:
66 Selected column index in the range ``0..6``.
67 """
68 ...
69
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.
72
73 This method is optional and not required by the GUI, but can be useful
74 for agents that support fine-grained move evaluation.
75
76 Args:
77 board (Board):
78 Current Connect-4 board position.
79 column (int):
80 Column index (0..6) of the move to evaluate.
81 first_guess (int):
82 Optional initial guess for iterative or search-based agents.
83 Implementations may safely ignore this parameter.
84
85 Returns:
86 int:
87 Evaluation score for the given move.
88 """
89 ...
int score_move(self, Board board, int column, int first_guess=0)
dict[int, int] score_all_moves(self, Board board)