diff --git a/nicsoft/lichess/__main__.py b/nicsoft/lichess/__main__.py index 0fa2068..5e78b6e 100644 --- a/nicsoft/lichess/__main__.py +++ b/nicsoft/lichess/__main__.py @@ -286,25 +286,43 @@ def get_game_state(self) -> GameState: return self.game_state def game_done(self, game_state: GameState = None) -> None: - """stop the thread, game should be over, or maybe a rage quit""" + """stop the thread, game should be over, or maybe a rage quit + @param - (GameState) a gamestate telling us how the game ended + @side-effect - changes the external board led's + + info on signals: + 1 - ring of lights + 2 - left half lit up + 3 - right half lit up + 4 - central line + 5 - cross in center + """ global logger, nl_inst logger.info("\nGame.game_done(GameState) entered.\n GameState %s", game_state) + # signal the side that won on the board by lighting up that side # if there is an external clock, display gameover message - if self.chess_clock: - if game_state is not None: - if game_state.winner: - if game_state.winner == "white": + if game_state is not None: + if game_state.winner: + if game_state.winner == "white": + if self.chess_clock: self.chess_clock.white_won() - elif game_state.winner == "black": # must be black + nl_inst.signal_lights(2) + elif game_state.winner == "black": + if self.chess_clock: self.chess_clock.black_won() - else: - # if no winner - self.chess_clock.game_over() - else: - # if no game state was given + nl_inst.signal_lights(3) + else: + # if no winner + self.chess_clock.game_over() + nl_inst.signal_lights(4) + else: + # if no game state was given + if self.chess_clock: self.chess_clock.game_over() + # signal we dont know wtf with a cross + self.signal_lights(5) - print("\n %%%%% GOOD GAME %%%%%\n") + print("\n[--- %%%%% GAME DONE %%%%% ---]\n") # tell the user and NicLink the game is through nl_inst.game_over.set() nl_inst.beep() @@ -347,8 +365,11 @@ def await_move_thread(self, fetch_list: list) -> None: "exiting Game.await_move_thread thread, everything is good." ) - def make_move(self, move) -> None: - """make a move in a lichess game""" + def make_move(self, move: str) -> None: + """make a move in a lichess game with self.gameId + @param - move: UCI move string ie: e4e5 + @side_effect: talkes to lichess, sending the move + """ global logger, nl_inst logger.info("move made: %s", move) @@ -548,8 +569,11 @@ def check_for_game_over(self, game_state: GameState) -> None: else: logger.debug("game not found to be over.") - def handle_chat_line(self, chat_line) -> None: - """handle when the other person types something in gamechat""" + def handle_chat_line(self, chat_line: str) -> None: + """handle when the other person types something in gamechat + @param: chat_line - the chat line got from lila + @side_effect: changes lights and beep's chess board + """ global nl_inst nl_inst.signal_lights(sig_num=1) print(chat_line) diff --git a/nicsoft/niclink/__main__.py b/nicsoft/niclink/__main__.py index e68f551..4e334af 100644 --- a/nicsoft/niclink/__main__.py +++ b/nicsoft/niclink/__main__.py @@ -183,7 +183,7 @@ def reset(self) -> None: self.kill_switch = threading.Event() self.start_game = threading.Event() - self.logger.info("NicLinkManager reset\n") + self.logger.debug("NicLinkManager reset\n") def set_led(self, square: str, status: bool) -> None: """set an LED at a given square to a status @@ -273,6 +273,8 @@ def signal_lights(self, sig_num: int) -> None: ie: 1 - ring of lights 2 - left half lit up 3 - right half lit up + 4 - central line + 5 - cross in center @side effect - change the light's on the chess board """ if sig_num == 1: @@ -312,7 +314,6 @@ def signal_lights(self, sig_num: int) -> None: self.set_all_LEDs(sig) elif sig_num == 3: """signal 3 - right half lit up""" - sig = np.array( [ "11111111", @@ -327,6 +328,36 @@ def signal_lights(self, sig_num: int) -> None: dtype=np.str_, ) self.set_all_LEDs(sig) + elif sig_num == 4: + """Signal 4 - center line""" + sig = np.array( + [ + "00000000", + "00000000", + "00000000", + "11111111", + "11111111", + "00000000", + "00000000", + "00000000", + ], + dtype=np.str_, + ) + elif sig_num == 5: + """Signal 5 - center cross""" + sig = np.array( + [ + "00011000", + "00011000", + "00011000", + "11111111", + "11111111", + "00011000", + "00011000", + "00011000", + ], + dtype=np.str_, + ) def get_FEN(self) -> str: """get the board FEN from chessboard"""