-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Game loop GUI #247
base: master
Are you sure you want to change the base?
Game loop GUI #247
Conversation
addresses #84 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
firmware/raspi/player.py
Outdated
@@ -69,6 +70,29 @@ def select_move(self, board): | |||
def __str__(self): | |||
return "CLHumanPlayer" | |||
|
|||
class GUIPlayer: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this GUIHumanPlayer
pls?
firmware/raspi/player.py
Outdated
@@ -69,6 +70,29 @@ def select_move(self, board): | |||
def __str__(self): | |||
return "CLHumanPlayer" | |||
|
|||
class GUIPlayer: | |||
""""GUI" class that allows playing with the chessboard through the gui. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Human class that allows playing with the chessboard through the gui.
"""
firmware/raspi/player.py
Outdated
"""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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls capitalize first word (Return) and change the double quote in it"s
to a single quote
firmware/raspi/player.py
Outdated
"""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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a single space between #
and start of comment and remove the newline between the docstring and the start of the function implementation
firmware/raspi/game.py
Outdated
"""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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, this should instead be:
if not self.board.engine.chess_board.move_stack:
return None
firmware/raspi/game.py
Outdated
|
||
if __name__ == '__main__': | ||
print("No main for this file, please use `cliinterface.py`") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add these three lines back
…with use of the verbose flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
firmware/raspi/chessboard.py
Outdated
""" | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update to:
"""Module containing class to display current board state.
Also contains some custom Exceptions.
Based on https://github.com/saavedra29/chess_tk
"""
firmware/raspi/game.py
Outdated
if __name__ == '__main__': | ||
print("No main for this file, please use `cliinterface.py`") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be indented
firmware/raspi/gui.py
Outdated
""" | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Module containing main GUI code to interact with game.py.
Based on https://github.com/saavedra29/chess_tk
"""
firmware/raspi/chessboard.py
Outdated
fullmove_number = 1 | ||
history = [] | ||
|
||
def __init__(self, pat=None): # pylint: disable=super-init-not-called unused-argument |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having this pylint disable comment, please add
super().__init__()
as the first line of the function and remove the pylint comment
firmware/raspi/chessboard.py
Outdated
piece = self[p1] | ||
try: | ||
dest = self[p2] | ||
except: # pylint: disable=W0702 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having this pylint disable comment, please change the line except:
to
except Exception as e:
and remove the pylint comment
firmware/raspi/gui.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls add space after last colon in prompt variable
firmware/raspi/gui.py
Outdated
root=tk.Tk() | ||
root.title("Knightr0\'s Gambit") | ||
|
||
#initialize gui |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after #
firmware/raspi/gui.py
Outdated
textbox=tk.Text(root) | ||
textbox.pack() | ||
|
||
#redirects print statements to gui |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after #
firmware/raspi/pieces.py
Outdated
""" | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Module containing helper GUI code for gui.py.
Based on https://github.com/saavedra29/chess_tk"""
firmware/raspi/pieces.py
Outdated
return module.__dict__[piece](color) | ||
|
||
class Piece(object): | ||
"""Chess piece class condainting color and shortname. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
condainting -> containing
Let me know if I can help with this PR in any way |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
firmware/raspi/game.py
Outdated
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please make this a static class variable called SLEEP_TIME
? And then update this and line 309 to use that variable.
firmware/raspi/game.py
Outdated
@@ -171,4 +172,4 @@ def process(self, player): | |||
raise ValueError("We shouldn't reach this point in the function.") | |||
|
|||
if __name__ == '__main__': | |||
print("No main for this file, please use `cliinterface.py`") | |||
print("No main for this file, please use `cliinterface.py`") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a newline at the end of the file.
firmware/raspi/gui.py
Outdated
@@ -0,0 +1,353 @@ | |||
"""Module containing main GUI code to interact with game.py. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please name this file gui_interface.py
for consistency with cli_interface.py
?
firmware/raspi/gui.py
Outdated
import tkinter as tk | ||
from tkinter import simpledialog |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simpledialog is in a separate module from tkinter (according to this SO) so it needs to be imported separately I believe
firmware/raspi/gui.py
Outdated
color1 = "#949494" | ||
color2 = "#f8f6f1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
firmware/raspi/gui.py
Outdated
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
firmware/raspi/pieces.py
Outdated
#def moves_available(self, pos): | ||
#return super(King, self).moves_available(pos.upper(), True, True, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not using, can remove.
firmware/raspi/pieces.py
Outdated
if board.alpha_notation(newLoc) not in board.occupied(self.color): | ||
allowed_moves.append(newLoc) | ||
|
||
# Checks if each rook can castsle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix spelling please
firmware/raspi/pieces.py
Outdated
shortname = "k" | ||
canCastle = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.