-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent_interface.py
More file actions
59 lines (47 loc) · 1.88 KB
/
agent_interface.py
File metadata and controls
59 lines (47 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
agent_interface.py
Provided by Andreas.
DO NOT MODIFY THIS CLASS. Your agent must inherit from it and implement the make_move method.
"""
import chess
import time
from abc import ABC, abstractmethod
class Agent(ABC):
"""
Abstract base class for all chess agents in the tournament.
"""
def __init__(self, board: chess.Board, color: chess.Color):
"""
Initialize the agent with the starting board and its color.
This is called once at the beginning of a game.
Args:
board (chess.Board): The initial game board state.
color (chess.Color): The color this agent is playing (chess.WHITE or chess.BLACK).
"""
self.board = board
self.color = color
@abstractmethod
def make_move(self, board: chess.Board, time_limit: float) -> chess.Move:
"""
The tournament driver calls this method to get the agent's move.
This is the main method that must be implemented by the student.
Args:
board (chess.Board): The current state of the game board.
time_limit (float): The maximum time (in seconds) the agent has to choose a move.
Returns:
chess.Move: The move chosen by the agent.
Raises:
NotImplementedError: If the subclass does not implement this method.
"""
raise NotImplementedError("The 'make_move' method must be implemented by the student's agent.")
def set_board(self, board: chess.Board) -> None:
"""
Update the agent's internal board state. Useful if you cache the board.
The tournament driver may call this to ensure the agent's board is synced.
Args:
board (chess.Board): The new, current board state.
"""
self.board = board
def __str__(self):
"""Returns a string identifier for the agent, using the class name."""
return self.__class__.__name__