Skip to content
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

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open

Game loop GUI #247

wants to merge 25 commits into from

Conversation

RuthShryock
Copy link
Collaborator

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

@RuthShryock RuthShryock requested a review from nashirj April 20, 2022 16:38
@RuthShryock
Copy link
Collaborator Author

RuthShryock commented Apr 20, 2022

addresses #84

Copy link
Member

@nashirj nashirj left a 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.

@@ -69,6 +70,29 @@ def select_move(self, board):
def __str__(self):
return "CLHumanPlayer"

class GUIPlayer:
Copy link
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?

@@ -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.
Copy link
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 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
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

"""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
Copy link
Member

@nashirj nashirj Apr 20, 2022

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 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
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 on lines 172 to 174

if __name__ == '__main__':
print("No main for this file, please use `cliinterface.py`")
Copy link
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

Copy link
Member

@nashirj nashirj left a 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.

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

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
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 on lines 173 to 174
if __name__ == '__main__':
print("No main for this file, please use `cliinterface.py`")
Copy link
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 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
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
"""

fullmove_number = 1
history = []

def __init__(self, pat=None): # pylint: disable=super-init-not-called unused-argument
Copy link
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

piece = self[p1]
try:
dest = self[p2]
except: # pylint: disable=W0702
Copy link
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

while True:
start = simpledialog.askstring(
title="Choose Piece Color",
prompt="Choose piece color ([w]hite, [b]lack, or [r]andom):").lower()
Copy link
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

root=tk.Tk()
root.title("Knightr0\'s Gambit")

#initialize gui
Copy link
Member

Choose a reason for hiding this comment

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

space after #

textbox=tk.Text(root)
textbox.pack()

#redirects print statements to gui
Copy link
Member

Choose a reason for hiding this comment

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

space after #

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

return module.__dict__[piece](color)

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

Choose a reason for hiding this comment

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

condainting -> containing

@nashirj
Copy link
Member

nashirj commented Aug 22, 2022

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

Copy link
Member

@nashirj nashirj left a 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.


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

@@ -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`")
Copy link
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.

@@ -0,0 +1,353 @@
"""Module containing main GUI code to interact with game.py.
Copy link
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 on lines 7 to 8
import tkinter as tk
from tkinter import simpledialog
Copy link
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
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 on lines 27 to 28
color1 = "#949494"
color2 = "#f8f6f1"
Copy link
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?

# 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
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 on lines 90 to 91
#def moves_available(self, pos):
#return super(King, self).moves_available(pos.upper(), True, True, 1)
Copy link
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.

if board.alpha_notation(newLoc) not in board.occupied(self.color):
allowed_moves.append(newLoc)

# Checks if each rook can castsle
Copy link
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 on lines 87 to 88
shortname = "k"
canCastle = True
Copy link
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.

else:
startpos, direction, enemy = 6, -1, "white"
allowed_moves = []
# Moving
Copy link
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