Skip to content

Commit

Permalink
dev: game_done re-write
Browse files Browse the repository at this point in the history
  • Loading branch information
nicvagn committed Jun 2, 2024
1 parent daf747a commit 5839be3
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 18 deletions.
56 changes: 40 additions & 16 deletions nicsoft/lichess/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
35 changes: 33 additions & 2 deletions nicsoft/niclink/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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",
Expand All @@ -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"""
Expand Down

0 comments on commit 5839be3

Please sign in to comment.