5
5
import chess
6
6
import chess .engine
7
7
8
- from zulip_bots .lib import BotHandler
8
+ from zulip_bots .lib import AbstractBotHandler
9
9
10
10
START_REGEX = re .compile ("start with other user$" )
11
11
START_COMPUTER_REGEX = re .compile ("start as (?P<user_color>white|black) with computer" )
@@ -24,7 +24,7 @@ def usage(self) -> str:
24
24
"Stockfish program on this computer."
25
25
)
26
26
27
- def initialize (self , bot_handler : BotHandler ) -> None :
27
+ def initialize (self , bot_handler : AbstractBotHandler ) -> None :
28
28
self .config_info = bot_handler .get_config_info ("chess" )
29
29
30
30
try :
@@ -36,7 +36,7 @@ def initialize(self, bot_handler: BotHandler) -> None:
36
36
# runner is testing or knows they won't be using an engine.
37
37
print ("That Stockfish doesn't exist. Continuing." )
38
38
39
- def handle_message (self , message : Dict [str , str ], bot_handler : BotHandler ) -> None :
39
+ def handle_message (self , message : Dict [str , str ], bot_handler : AbstractBotHandler ) -> None :
40
40
content = message ["content" ]
41
41
42
42
if content == "" :
@@ -76,7 +76,7 @@ def handle_message(self, message: Dict[str, str], bot_handler: BotHandler) -> No
76
76
elif resign_regex_match :
77
77
self .resign (message , bot_handler , last_fen )
78
78
79
- def start (self , message : Dict [str , str ], bot_handler : BotHandler ) -> None :
79
+ def start (self , message : Dict [str , str ], bot_handler : AbstractBotHandler ) -> None :
80
80
"""Starts a game with another user, with the current user as white.
81
81
Replies to the bot handler.
82
82
@@ -93,7 +93,7 @@ def start(self, message: Dict[str, str], bot_handler: BotHandler) -> None:
93
93
bot_handler .storage .put ("last_fen" , new_board .fen ())
94
94
95
95
def start_computer (
96
- self , message : Dict [str , str ], bot_handler : BotHandler , is_white_user : bool
96
+ self , message : Dict [str , str ], bot_handler : AbstractBotHandler , is_white_user : bool
97
97
) -> None :
98
98
"""Starts a game with the computer. Replies to the bot handler.
99
99
@@ -123,7 +123,7 @@ def start_computer(
123
123
)
124
124
125
125
def validate_board (
126
- self , message : Dict [str , str ], bot_handler : BotHandler , fen : str
126
+ self , message : Dict [str , str ], bot_handler : AbstractBotHandler , fen : str
127
127
) -> Optional [chess .Board ]:
128
128
"""Validates a board based on its FEN string. Replies to the bot
129
129
handler if there is an error with the board.
@@ -147,7 +147,7 @@ def validate_board(
147
147
def validate_move (
148
148
self ,
149
149
message : Dict [str , str ],
150
- bot_handler : BotHandler ,
150
+ bot_handler : AbstractBotHandler ,
151
151
last_board : chess .Board ,
152
152
move_san : str ,
153
153
is_computer : object ,
@@ -180,7 +180,7 @@ def validate_move(
180
180
return move
181
181
182
182
def check_game_over (
183
- self , message : Dict [str , str ], bot_handler : BotHandler , new_board : chess .Board
183
+ self , message : Dict [str , str ], bot_handler : AbstractBotHandler , new_board : chess .Board
184
184
) -> bool :
185
185
"""Checks if a game is over due to
186
186
- checkmate,
@@ -224,7 +224,7 @@ def check_game_over(
224
224
return False
225
225
226
226
def move (
227
- self , message : Dict [str , str ], bot_handler : BotHandler , last_fen : str , move_san : str
227
+ self , message : Dict [str , str ], bot_handler : AbstractBotHandler , last_fen : str , move_san : str
228
228
) -> None :
229
229
"""Makes a move for a user in a game with another user. Replies to
230
230
the bot handler.
@@ -256,7 +256,7 @@ def move(
256
256
bot_handler .storage .put ("last_fen" , new_board .fen ())
257
257
258
258
def move_computer (
259
- self , message : Dict [str , str ], bot_handler : BotHandler , last_fen : str , move_san : str
259
+ self , message : Dict [str , str ], bot_handler : AbstractBotHandler , last_fen : str , move_san : str
260
260
) -> None :
261
261
"""Preforms a move for a user in a game with the computer and then
262
262
makes the computer's move. Replies to the bot handler. Unlike `move`,
@@ -306,7 +306,7 @@ def move_computer(
306
306
bot_handler .storage .put ("last_fen" , new_board_after_computer_move .fen ())
307
307
308
308
def move_computer_first (
309
- self , message : Dict [str , str ], bot_handler : BotHandler , last_fen : str
309
+ self , message : Dict [str , str ], bot_handler : AbstractBotHandler , last_fen : str
310
310
) -> None :
311
311
"""Preforms a move for the computer without having the user go first in
312
312
a game with the computer. Replies to the bot handler. Like
@@ -345,7 +345,9 @@ def move_computer_first(
345
345
# `bot_handler`'s `storage` only accepts `str` values.
346
346
bot_handler .storage .put ("is_with_computer" , str (True ))
347
347
348
- def resign (self , message : Dict [str , str ], bot_handler : BotHandler , last_fen : str ) -> None :
348
+ def resign (
349
+ self , message : Dict [str , str ], bot_handler : AbstractBotHandler , last_fen : str
350
+ ) -> None :
349
351
"""Resigns the game for the current player.
350
352
351
353
Parameters:
0 commit comments