bstraehle commited on
Commit
fd24688
·
verified ·
1 Parent(s): 528bd46

Update multi_agent.py

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