Skip to content

Commit

Permalink
Fixed a KeyError in Game.py and added some extra Exception output
Browse files Browse the repository at this point in the history
  • Loading branch information
Fizzizist committed Nov 8, 2022
1 parent c4099ec commit aa2b056
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions lichs/Game.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def handle_state_change(self, game_state):

global chess_board

if game_state[self.color[0].lower() + "draw"] == True:
if game_state.get(self.color[0].lower() + "draw") is True:
self.handle_draw_state(game_state)
elif game_state["status"] == "resign":
print("The opponent resigned. Congrats!")
Expand Down Expand Up @@ -84,8 +84,9 @@ def handle_state_change(self, game_state):
self.clock['white'] -= datetime.datetime.now() - move_start
else:
self.clock['black'] -= datetime.datetime.now() - move_start
except:
except Exception as e:
print("You can't make that move. Try again!")
print(f"Reason: {e}")
continue
break

Expand Down Expand Up @@ -120,8 +121,9 @@ def white_first_move(self):
else:
self.board.make_move(self.game_id, chess_board.parse_san(move))
chess_board.push_san(move)
except:
except Exception as e:
print("You can't make that move. Try again!")
print(f'Reason: {e}')
continue
break

Expand Down Expand Up @@ -159,4 +161,5 @@ def display_board(self):
# print clock
print("[%02d:%02d : %02d:%02d]" % (self.clock['white'].minute, self.clock['white'].second,
self.clock['black'].minute, self.clock['black'].second))
print()
print()

Empty file removed lichs/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions lichs/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from pathlib import Path
from getpass import getpass

from lichs.Game import Game
from lichs.api_key import set_api
from Game import Game
from api_key import set_api

token_file = Path(__file__).parent.absolute() / "token.key"

Expand Down
File renamed without changes.

0 comments on commit aa2b056

Please sign in to comment.