bstraehle commited on
Commit
f2bb71c
·
verified ·
1 Parent(s): 020fcea

Update multi_agent.py

Browse files
Files changed (1) hide show
  1. multi_agent.py +40 -40
multi_agent.py CHANGED
@@ -2,52 +2,52 @@ import chess, chess.svg, math
2
  from autogen import ConversableAgent, register_function
3
  from typing_extensions import Annotated
4
 
5
- def get_legal_moves() -> Annotated[str, "A list of legal moves in UCI format"]:
6
- return "Possible moves are: " + ",".join(
7
- [str(move) for move in board.legal_moves]
8
- )
9
-
10
- def make_move(move: Annotated[str, "A move in UCI format."]) -> Annotated[str, "Result of the move."]:
11
- move = chess.Move.from_uci(move)
12
- board.push_uci(str(move))
13
- global made_move
14
- made_move = True
15
-
16
- board_svgs.append(chess.svg.board(
17
- board,
18
- arrows=[(move.from_square, move.to_square)],
19
- fill={move.from_square: "gray"},
20
- size=250
21
- ))
22
-
23
- piece = board.piece_at(move.to_square)
24
- piece_symbol = piece.unicode_symbol()
25
- piece_name = (
26
- chess.piece_name(piece.piece_type).capitalize()
27
- if piece_symbol.isupper()
28
- else chess.piece_name(piece.piece_type)
29
- )
30
-
31
- return f"Moved {piece_name} ({piece_symbol}) from "\
32
- f"{chess.SQUARE_NAMES[move.from_square]} to "\
33
- f"{chess.SQUARE_NAMES[move.to_square]}."
34
-
35
- def check_made_move(msg):
36
- global made_move
37
-
38
- if made_move:
39
- made_move = False
40
- return True
41
- else:
42
- return False
43
-
44
  class MultiAgent:
45
  made_move = False
46
 
47
  board = chess.Board()
48
  board_svgs = []
49
 
50
- def get_num_turns(self, num_moves):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  # Each turn includes two moves (one by each player)
52
  # The first move by player black kicks off the chat
53
  # The first move by player white starts the game
 
2
  from autogen import ConversableAgent, register_function
3
  from typing_extensions import Annotated
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  class MultiAgent:
6
  made_move = False
7
 
8
  board = chess.Board()
9
  board_svgs = []
10
 
11
+ def get_legal_moves() -> Annotated[str, "A list of legal moves in UCI format"]:
12
+ return "Possible moves are: " + ",".join(
13
+ [str(move) for move in board.legal_moves]
14
+ )
15
+
16
+ def make_move(move: Annotated[str, "A move in UCI format."]) -> Annotated[str, "Result of the move."]:
17
+ move = chess.Move.from_uci(move)
18
+ board.push_uci(str(move))
19
+ global made_move
20
+ made_move = True
21
+
22
+ board_svgs.append(chess.svg.board(
23
+ board,
24
+ arrows=[(move.from_square, move.to_square)],
25
+ fill={move.from_square: "gray"},
26
+ size=250
27
+ ))
28
+
29
+ piece = board.piece_at(move.to_square)
30
+ piece_symbol = piece.unicode_symbol()
31
+ piece_name = (
32
+ chess.piece_name(piece.piece_type).capitalize()
33
+ if piece_symbol.isupper()
34
+ else chess.piece_name(piece.piece_type)
35
+ )
36
+
37
+ return f"Moved {piece_name} ({piece_symbol}) from "\
38
+ f"{chess.SQUARE_NAMES[move.from_square]} to "\
39
+ f"{chess.SQUARE_NAMES[move.to_square]}."
40
+
41
+ def check_made_move(msg):
42
+ global made_move
43
+
44
+ if made_move:
45
+ made_move = False
46
+ return True
47
+ else:
48
+ return False
49
+
50
+ def get_num_turns(num_moves):
51
  # Each turn includes two moves (one by each player)
52
  # The first move by player black kicks off the chat
53
  # The first move by player white starts the game