bstraehle commited on
Commit
85b163a
·
verified ·
1 Parent(s): 293293c

Update multi_agent.py

Browse files
Files changed (1) hide show
  1. multi_agent.py +9 -6
multi_agent.py CHANGED
@@ -1,11 +1,14 @@
1
- import chess, chess.svg
2
  from autogen import ConversableAgent, register_function
3
  from typing_extensions import Annotated
4
 
5
  made_move = False
6
 
7
  board = chess.Board()
8
- board_svgs = []
 
 
 
9
 
10
  def get_legal_moves() -> Annotated[str, "A list of legal moves in UCI format"]:
11
  return "Possible moves are: " + ",".join(
@@ -18,12 +21,12 @@ def make_move(move: Annotated[str, "A move in UCI format."]) -> Annotated[str, "
18
  global made_move
19
  made_move = True
20
 
21
- svg = chess.svg.board(
22
  board,
23
  arrows=[(move.from_square, move.to_square)],
24
  fill={move.from_square: "gray"},
25
  size=200
26
- )
27
 
28
  piece = board.piece_at(move.to_square)
29
  piece_symbol = piece.unicode_symbol()
@@ -33,7 +36,7 @@ def make_move(move: Annotated[str, "A move in UCI format."]) -> Annotated[str, "
33
  else chess.piece_name(piece.piece_type)
34
  )
35
 
36
- board_svgs.append(svg)
37
 
38
  return f"Moved {piece_name} ({piece_symbol}) from "\
39
  f"{chess.SQUARE_NAMES[move.from_square]} to "\
@@ -141,7 +144,7 @@ def run_multi_agent(llm_white, llm_black, num_turns):
141
  player = "Player White"
142
 
143
  if turn_num > 0:
144
- result += f"**{player}, Move {turn_num}**\n<br>{chat.get('content')}<br>{board_svgs[turn_num - 1]}<br>"
145
 
146
  turn_num += 1
147
 
 
1
+ import cairosvg, chess, chess.svg, os
2
  from autogen import ConversableAgent, register_function
3
  from typing_extensions import Annotated
4
 
5
  made_move = False
6
 
7
  board = chess.Board()
8
+ board_pngs = []
9
+
10
+ def convert_svg_to_png(svg_file_path: str, png_file_path: str) -> None:
11
+ cairosvg.svg2png(url=svg_file_path, write_to=png_file_path)
12
 
13
  def get_legal_moves() -> Annotated[str, "A list of legal moves in UCI format"]:
14
  return "Possible moves are: " + ",".join(
 
21
  global made_move
22
  made_move = True
23
 
24
+ png = convert_svg_to_png(chess.svg.board(
25
  board,
26
  arrows=[(move.from_square, move.to_square)],
27
  fill={move.from_square: "gray"},
28
  size=200
29
+ ))
30
 
31
  piece = board.piece_at(move.to_square)
32
  piece_symbol = piece.unicode_symbol()
 
36
  else chess.piece_name(piece.piece_type)
37
  )
38
 
39
+ board_pngs.append(png)
40
 
41
  return f"Moved {piece_name} ({piece_symbol}) from "\
42
  f"{chess.SQUARE_NAMES[move.from_square]} to "\
 
144
  player = "Player White"
145
 
146
  if turn_num > 0:
147
+ result += f"**{player}, Move {turn_num}**\n<br>{chat.get('content')}<br>{board_pngs[turn_num - 1]}<br>"
148
 
149
  turn_num += 1
150