Update multi_agent.py
Browse files- multi_agent.py +12 -8
multi_agent.py
CHANGED
@@ -4,16 +4,18 @@ from typing_extensions import Annotated
|
|
4 |
|
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 "
|
11 |
[str(move) for move in board.legal_moves]
|
12 |
-
)
|
13 |
|
14 |
def make_move(move: Annotated[str, "A move in UCI format."]) -> Annotated[str, "Result of the move."]:
|
15 |
move = chess.Move.from_uci(move)
|
16 |
board.push_uci(str(move))
|
|
|
17 |
global made_move
|
18 |
made_move = True
|
19 |
|
@@ -59,8 +61,10 @@ def get_num_turns(num_moves):
|
|
59 |
|
60 |
def initialize():
|
61 |
global board, board_svgs, made_move
|
|
|
62 |
board = chess.Board()
|
63 |
board_svgs = []
|
|
|
64 |
made_move = False
|
65 |
|
66 |
def run_multi_agent(llm_white, llm_black, num_moves):
|
@@ -80,18 +84,18 @@ 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()
|
84 |
-
"Then call make_move(move) to make
|
85 |
-
"
|
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()
|
93 |
-
"Then call make_move(move) to make
|
94 |
-
"
|
95 |
llm_config=llm_config_black,
|
96 |
)
|
97 |
|
|
|
4 |
|
5 |
board = None
|
6 |
board_svgs = None
|
7 |
+
|
8 |
made_move = None
|
9 |
|
10 |
def get_legal_moves() -> Annotated[str, "A list of legal moves in UCI format"]:
|
11 |
+
return "Legal moves are: " + ",".join(
|
12 |
[str(move) for move in board.legal_moves]
|
13 |
+
) + "."
|
14 |
|
15 |
def make_move(move: Annotated[str, "A move in UCI format."]) -> Annotated[str, "Result of the move."]:
|
16 |
move = chess.Move.from_uci(move)
|
17 |
board.push_uci(str(move))
|
18 |
+
|
19 |
global made_move
|
20 |
made_move = True
|
21 |
|
|
|
61 |
|
62 |
def initialize():
|
63 |
global board, board_svgs, made_move
|
64 |
+
|
65 |
board = chess.Board()
|
66 |
board_svgs = []
|
67 |
+
|
68 |
made_move = False
|
69 |
|
70 |
def run_multi_agent(llm_white, llm_black, num_moves):
|
|
|
84 |
player_white = ConversableAgent(
|
85 |
name="Player White",
|
86 |
system_message="You are a chess Grandmaster and you play as white. "
|
87 |
+
"First call get_legal_moves() to get a list of legal moves. "
|
88 |
+
"Then study the returned moves and call make_move(move) to make the best move. "
|
89 |
+
"Finally analyze the move in format: **Analysis:** move in UCI format, piece symbol, unordered list of 3 items.",
|
90 |
llm_config=llm_config_white,
|
91 |
)
|
92 |
|
93 |
player_black = ConversableAgent(
|
94 |
name="Player Black",
|
95 |
system_message="You are a chess Grandmaster and you play as black. "
|
96 |
+
"First call get_legal_moves() to get a list of legal moves. "
|
97 |
+
"Then study the returned moves and call make_move(move) to make the best move. "
|
98 |
+
"Finally analyze the move in format: **Analysis:** move in UCI format, piece symbol, unordered list of 3 items.",
|
99 |
llm_config=llm_config_black,
|
100 |
)
|
101 |
|