Game loop GUI#247
Conversation
|
addresses #84 |
nashirj
left a comment
There was a problem hiding this comment.
I'm leaving you a partial review, I'll continue reviewing gui.py, pieces.py and chessboard.py in the meantime and make a second review for those files.
| def __str__(self): | ||
| return "CLHumanPlayer" | ||
|
|
||
| class GUIPlayer: |
There was a problem hiding this comment.
Can you make this GUIHumanPlayer pls?
| return "CLHumanPlayer" | ||
|
|
||
| class GUIPlayer: | ||
| """"GUI" class that allows playing with the chessboard through the gui. |
There was a problem hiding this comment.
"""Human class that allows playing with the chessboard through the gui.
"""| """returns None until a new move is selected on the GUI | ||
| (which can only be done if it"s the GUI player"s turn) |
There was a problem hiding this comment.
Pls capitalize first word (Return) and change the double quote in it"s to a single quote
| """returns None until a new move is selected on the GUI | ||
| (which can only be done if it"s the GUI player"s turn) | ||
| """ | ||
| #Note next move can be None |
There was a problem hiding this comment.
Please add a single space between # and start of comment and remove the newline between the docstring and the start of the function implementation
| """if self.board.engine.chess_board.move_stack: | ||
| return None""" | ||
| #this was always defaulting to true and not allowing access to move |
There was a problem hiding this comment.
You are right, this should instead be:
if not self.board.engine.chess_board.move_stack:
return None|
|
||
| if __name__ == '__main__': | ||
| print("No main for this file, please use `cliinterface.py`") |
There was a problem hiding this comment.
Please add these three lines back
…with use of the verbose flag
nashirj
left a comment
There was a problem hiding this comment.
Works really well! One thing I noticed (aside from the comments I left you) is that castling does not work yet for the GUI player. When the king is selected, if castling is available, the square for castling should be highlighted for the king. I attached a screenshot of lichess with a position that has castling legal so you can see what it looks like.
| """ | ||
| adapted code from: | ||
| * Title: chess_tk | ||
| * Author: Guatam Sharma | ||
| * Date: May 19, 2016 | ||
| * Availability: https://github.com/saavedra29/chess_tk | ||
| """ |
There was a problem hiding this comment.
Please update to:
"""Module containing class to display current board state.
Also contains some custom Exceptions.
Based on https://github.com/saavedra29/chess_tk
"""| if __name__ == '__main__': | ||
| print("No main for this file, please use `cliinterface.py`") No newline at end of file |
| """ | ||
| adapted code from: | ||
| * Title: chess_tk | ||
| * Author: Guatam Sharma | ||
| * Date: May 19, 2016 | ||
| * Availability: https://github.com/saavedra29/chess_tk | ||
| """ |
There was a problem hiding this comment.
"""Module containing main GUI code to interact with game.py.
Based on https://github.com/saavedra29/chess_tk
"""| fullmove_number = 1 | ||
| history = [] | ||
|
|
||
| def __init__(self, pat=None): # pylint: disable=super-init-not-called unused-argument |
There was a problem hiding this comment.
Instead of having this pylint disable comment, please add
super().__init__()as the first line of the function and remove the pylint comment
| piece = self[p1] | ||
| try: | ||
| dest = self[p2] | ||
| except: # pylint: disable=W0702 |
There was a problem hiding this comment.
Instead of having this pylint disable comment, please change the line except: to
except Exception as e:and remove the pylint comment
| while True: | ||
| start = simpledialog.askstring( | ||
| title="Choose Piece Color", | ||
| prompt="Choose piece color ([w]hite, [b]lack, or [r]andom):").lower() |
There was a problem hiding this comment.
pls add space after last colon in prompt variable
| root=tk.Tk() | ||
| root.title("Knightr0\'s Gambit") | ||
|
|
||
| #initialize gui |
| textbox=tk.Text(root) | ||
| textbox.pack() | ||
|
|
||
| #redirects print statements to gui |
| """ | ||
| adapted code from: | ||
| * Title: chess_tk | ||
| * Author: Guatam Sharma | ||
| * Date: May 19, 2016 | ||
| * Availability: https://github.com/saavedra29/chess_tk | ||
|
|
||
| """ |
There was a problem hiding this comment.
"""Module containing helper GUI code for gui.py.
Based on https://github.com/saavedra29/chess_tk"""| return module.__dict__[piece](color) | ||
|
|
||
| class Piece(object): | ||
| """Chess piece class condainting color and shortname. |
|
Let me know if I can help with this PR in any way |
nashirj
left a comment
There was a problem hiding this comment.
Thanks for working on this, overall looks really good. Left some comments but also have some requests for behavior changes:
- If you click a piece and then click it again without making a move, it should no longer be highlighted.
- The castling behavior doesn't work as expected; the GUI doesn't update the rook movement until after the next player's turn. Can we make it so that if the king makes a castling move, both the king and the rook positions are updated simultaneously?
- About ten moves into the game playing as white (I tried twice), the game stops responding - it's white's turn, and after I click for where I want to go, the game freezes.
| if arduino_status.status == status.ArduinoStatus.EXECUTING_MOVE: | ||
| # Wait for move in progress to finish executing | ||
| time.sleep(1) # reduce the amount of polling while waiting for move to finish | ||
| time.sleep(.01) # reduce the amount of polling while waiting for move to finish |
There was a problem hiding this comment.
Can you please make this a static class variable called SLEEP_TIME? And then update this and line 309 to use that variable.
|
|
||
| if __name__ == '__main__': | ||
| print("No main for this file, please use `cliinterface.py`") | ||
| print("No main for this file, please use `cliinterface.py`") No newline at end of file |
There was a problem hiding this comment.
Please add a newline at the end of the file.
| @@ -0,0 +1,353 @@ | |||
| """Module containing main GUI code to interact with game.py. | |||
There was a problem hiding this comment.
Can you please name this file gui_interface.py for consistency with cli_interface.py?
| import tkinter as tk | ||
| from tkinter import simpledialog |
There was a problem hiding this comment.
If you're importing tkinter, you don't need to also import simpledialog, you can do tk.simpledialog (I think).
There was a problem hiding this comment.
Simpledialog is in a separate module from tkinter (according to this SO) so it needs to be imported separately I believe
| color1 = "#949494" | ||
| color2 = "#f8f6f1" |
There was a problem hiding this comment.
I am guessing these are for the piece colors? Can you please rename them to something like COLOR_BLACK and COLOR_WHITE or something like that?
| # Need to empty move queue to play out final captures, etc (if any) before ending | ||
| while self.game.board.msg_queue: | ||
| self.game.process(None) | ||
| #gui player can no longer make moves |
There was a problem hiding this comment.
Can you please update all your comments to have a space between the # and the beginning of the comment? And please capitalize the first word of the comments.
| #def moves_available(self, pos): | ||
| #return super(King, self).moves_available(pos.upper(), True, True, 1) |
| if board.alpha_notation(newLoc) not in board.occupied(self.color): | ||
| allowed_moves.append(newLoc) | ||
|
|
||
| # Checks if each rook can castsle |
| shortname = "k" | ||
| canCastle = True |
There was a problem hiding this comment.
Please update all camel case variable names to be snake case instead: e.g. can_castle instead of canCastle.
| else: | ||
| startpos, direction, enemy = 6, -1, "white" | ||
| allowed_moves = [] | ||
| # Moving |
There was a problem hiding this comment.
The function name is moves_available (which makes it seem like it would return the allowed_moves) but this comment makes it seem like this function is moving the pieces, is that what's happening?

Might need to reconfigure some of the invalid moves, pawn promotion situation, and ending the game.