Update multi_agent.py
Browse files- multi_agent.py +22 -6
multi_agent.py
CHANGED
@@ -5,6 +5,7 @@ from typing_extensions import Annotated
|
|
5 |
board = None
|
6 |
board_svgs = None
|
7 |
made_move = None
|
|
|
8 |
|
9 |
def get_legal_moves() -> Annotated[str, "A list of legal moves in UCI format"]:
|
10 |
return "Possible moves are: " + ",".join(
|
@@ -36,6 +37,9 @@ def make_move(move: Annotated[str, "A move in UCI format."]) -> Annotated[str, "
|
|
36 |
f"{chess.SQUARE_NAMES[move.from_square]} to "\
|
37 |
f"{chess.SQUARE_NAMES[move.to_square]}."
|
38 |
|
|
|
|
|
|
|
39 |
def check_made_move(msg):
|
40 |
global made_move
|
41 |
|
@@ -45,6 +49,14 @@ def check_made_move(msg):
|
|
45 |
else:
|
46 |
return False
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
def get_num_turns(num_moves):
|
49 |
# Each turn includes two moves (one by each player)
|
50 |
# The first move by player black kicks off the chat
|
@@ -80,19 +92,23 @@ def run_multi_agent(llm_white, llm_black, num_moves):
|
|
80 |
player_white = ConversableAgent(
|
81 |
name="Player White",
|
82 |
system_message="You are a chess Grandmaster and you play as white. "
|
83 |
-
"First call get_legal_moves(), to get a list of legal moves.
|
84 |
-
"
|
|
|
85 |
"Analyze the move in 3 bullet points. Respond in format **Analysis:** move in UCI format, unordered list.",
|
86 |
-
llm_config=llm_config_white
|
|
|
87 |
)
|
88 |
|
89 |
player_black = ConversableAgent(
|
90 |
name="Player Black",
|
91 |
system_message="You are a chess Grandmaster and you play as black. "
|
92 |
-
"First call get_legal_moves(), to get a list of legal moves.
|
93 |
-
"
|
|
|
94 |
"Analyze the move in 3 bullet points. Respond in format **Analysis:** move in UCI format, unordered list.",
|
95 |
-
llm_config=llm_config_black
|
|
|
96 |
)
|
97 |
|
98 |
for caller in [player_white, player_black]:
|
|
|
5 |
board = None
|
6 |
board_svgs = None
|
7 |
made_move = None
|
8 |
+
gaem_over = False
|
9 |
|
10 |
def get_legal_moves() -> Annotated[str, "A list of legal moves in UCI format"]:
|
11 |
return "Possible moves are: " + ",".join(
|
|
|
37 |
f"{chess.SQUARE_NAMES[move.from_square]} to "\
|
38 |
f"{chess.SQUARE_NAMES[move.to_square]}."
|
39 |
|
40 |
+
def game_over():
|
41 |
+
game_over = True
|
42 |
+
|
43 |
def check_made_move(msg):
|
44 |
global made_move
|
45 |
|
|
|
49 |
else:
|
50 |
return False
|
51 |
|
52 |
+
def check_game_over(msg):
|
53 |
+
global game_over
|
54 |
+
|
55 |
+
if game_over:
|
56 |
+
return True
|
57 |
+
else:
|
58 |
+
return False
|
59 |
+
|
60 |
def get_num_turns(num_moves):
|
61 |
# Each turn includes two moves (one by each player)
|
62 |
# The first move by player black kicks off the chat
|
|
|
92 |
player_white = ConversableAgent(
|
93 |
name="Player White",
|
94 |
system_message="You are a chess Grandmaster and you play as white. "
|
95 |
+
"First call get_legal_moves(), to get a list of legal moves. "
|
96 |
+
"If there is no legal move, call game_over() "
|
97 |
+
"Else call make_move(move) to make a legal move. "
|
98 |
"Analyze the move in 3 bullet points. Respond in format **Analysis:** move in UCI format, unordered list.",
|
99 |
+
llm_config=llm_config_white,
|
100 |
+
is_termination_msg=check_game_over
|
101 |
)
|
102 |
|
103 |
player_black = ConversableAgent(
|
104 |
name="Player Black",
|
105 |
system_message="You are a chess Grandmaster and you play as black. "
|
106 |
+
"First call get_legal_moves(), to get a list of legal moves. "
|
107 |
+
"If there is no legal move, call game_over() "
|
108 |
+
"Else call make_move(move) to make a legal move. "
|
109 |
"Analyze the move in 3 bullet points. Respond in format **Analysis:** move in UCI format, unordered list.",
|
110 |
+
llm_config=llm_config_black,
|
111 |
+
is_termination_msg=check_game_over
|
112 |
)
|
113 |
|
114 |
for caller in [player_white, player_black]:
|