Skip to content

Game loop GUI#247

Open
RuthTurk wants to merge 25 commits into
masterfrom
gui-game-loop
Open

Game loop GUI#247
RuthTurk wants to merge 25 commits into
masterfrom
gui-game-loop

Conversation

@RuthTurk

Copy link
Copy Markdown
Collaborator

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

@RuthTurk
RuthTurk requested a review from nashirj April 20, 2022 16:38
@RuthTurk

RuthTurk commented Apr 20, 2022

Copy link
Copy Markdown
Collaborator Author

addresses #84

@nashirj nashirj left a comment

Copy link
Copy Markdown
Member

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.

Comment thread firmware/raspi/player.py Outdated
def __str__(self):
return "CLHumanPlayer"

class GUIPlayer:

Copy link
Copy Markdown
Member

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?

Comment thread firmware/raspi/player.py Outdated
return "CLHumanPlayer"

class GUIPlayer:
""""GUI" class that allows playing with the chessboard through the gui.

Copy link
Copy Markdown
Member

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.
"""

Comment thread firmware/raspi/player.py Outdated
Comment on lines +80 to +81
"""returns None until a new move is selected on the GUI
(which can only be done if it"s the GUI player"s turn)

Copy link
Copy Markdown
Member

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

Comment thread 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

@nashirj nashirj Apr 20, 2022

Copy link
Copy Markdown
Member

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

Comment thread firmware/raspi/game.py Outdated
Comment on lines +48 to +50
"""if self.board.engine.chess_board.move_stack:
return None"""
#this was always defaulting to true and not allowing access to move

Copy link
Copy Markdown
Member

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

Comment thread firmware/raspi/game.py
Comment on lines -172 to -174

if __name__ == '__main__':
print("No main for this file, please use `cliinterface.py`")

Copy link
Copy Markdown
Member

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

@nashirj nashirj left a comment

Copy link
Copy Markdown
Member

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.

Screen Shot 2022-05-07 at 11 11 14 PM

Comment thread firmware/raspi/chessboard.py Outdated
Comment on lines +1 to +7
"""
adapted code from:
* Title: chess_tk
* Author: Guatam Sharma
* Date: May 19, 2016
* Availability: https://github.com/saavedra29/chess_tk
"""

Copy link
Copy Markdown
Member

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
"""

Comment thread firmware/raspi/game.py Outdated
Comment on lines +173 to +174
if __name__ == '__main__':
print("No main for this file, please use `cliinterface.py`") No newline at end of file

Copy link
Copy Markdown
Member

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

Comment thread firmware/raspi/gui.py Outdated
Comment on lines +1 to +7
"""
adapted code from:
* Title: chess_tk
* Author: Guatam Sharma
* Date: May 19, 2016
* Availability: https://github.com/saavedra29/chess_tk
"""

Copy link
Copy Markdown
Member

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
"""

Comment thread firmware/raspi/chessboard.py Outdated
fullmove_number = 1
history = []

def __init__(self, pat=None): # pylint: disable=super-init-not-called unused-argument

Copy link
Copy Markdown
Member

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

Comment thread firmware/raspi/chessboard.py Outdated
piece = self[p1]
try:
dest = self[p2]
except: # pylint: disable=W0702

Copy link
Copy Markdown
Member

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

Comment thread 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()

Copy link
Copy Markdown
Member

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

Comment thread firmware/raspi/gui.py Outdated
root=tk.Tk()
root.title("Knightr0\'s Gambit")

#initialize gui

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after #

Comment thread firmware/raspi/gui.py Outdated
textbox=tk.Text(root)
textbox.pack()

#redirects print statements to gui

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after #

Comment thread firmware/raspi/pieces.py Outdated
Comment on lines +1 to +8
"""
adapted code from:
* Title: chess_tk
* Author: Guatam Sharma
* Date: May 19, 2016
* Availability: https://github.com/saavedra29/chess_tk

"""

Copy link
Copy Markdown
Member

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"""

Comment thread firmware/raspi/pieces.py Outdated
return module.__dict__[piece](color)

class Piece(object):
"""Chess piece class condainting color and shortname.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

condainting -> containing

@nashirj

nashirj commented Aug 22, 2022

Copy link
Copy Markdown
Member

Let me know if I can help with this PR in any way

@nashirj nashirj left a comment

Copy link
Copy Markdown
Member

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.

Comment thread 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

Copy link
Copy Markdown
Member

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.

Comment thread firmware/raspi/game.py Outdated

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

Copy link
Copy Markdown
Member

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.

Comment thread firmware/raspi/gui.py
@@ -0,0 +1,353 @@
"""Module containing main GUI code to interact with game.py.

Copy link
Copy Markdown
Member

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?

Comment thread firmware/raspi/gui.py
Comment on lines +7 to +8
import tkinter as tk
from tkinter import simpledialog

Copy link
Copy Markdown
Member

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).

Copy link
Copy Markdown
Collaborator Author

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

Comment thread firmware/raspi/gui.py Outdated
Comment on lines +27 to +28
color1 = "#949494"
color2 = "#f8f6f1"

Copy link
Copy Markdown
Member

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?

Comment thread 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

Copy link
Copy Markdown
Member

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.

Comment thread firmware/raspi/pieces.py Outdated
Comment on lines +90 to +91
#def moves_available(self, pos):
#return super(King, self).moves_available(pos.upper(), True, True, 1)

Copy link
Copy Markdown
Member

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.

Comment thread 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix spelling please

Comment thread firmware/raspi/pieces.py Outdated
Comment on lines +87 to +88
shortname = "k"
canCastle = True

Copy link
Copy Markdown
Member

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.

Comment thread firmware/raspi/pieces.py
else:
startpos, direction, enemy = 6, -1, "white"
allowed_moves = []
# Moving

Copy link
Copy Markdown
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants