-
Notifications
You must be signed in to change notification settings - Fork 1
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
Adding some notes #1
base: master
Are you sure you want to change the base?
Conversation
# ask the player for the x and y values of the piece which they'd like to move from and to. | ||
move = askForMove(f"It's {str(game.whichTurn)}'s turn") | ||
userSelection = game.gameBoard.getPiece(*(move[0].getXY())) |
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.
@mknowles36 on line 177, is the asterisk being used here to unpack the tuple of ints which the .getxy() method returns? If not, what is the asterisk doing?
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.
Yup - that's exactly what the asterisk is for.
self.rank = int(rank) - 1 | ||
|
||
def __str__(self): | ||
return f"{str(self.file_codes[self.file])}{str(self.rank + 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.
@mknowles36 question: why do you initialize self.rank (line 26) as being the rank minus one, only to add one to self.rank when you're printing self.rank (line 29)?
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.
Right - so the idea was that I wanted the internally-stored rank and file in SquareLocation to be in a standard index-of-array form (ie., 0-based). So that's why I subtracted ord('a') from the file and 1 from the rank. From the standard form, it can then be converted to either back to Algebraic Notation form (in str()) or to X/Y coordinates of the storage array (in getXY()) via the transforms in those corresponding methods (ie adding 1 back to the rank and effectively adding 'a' back to the file (via a lookup table).
Having said that, you do make a point that storing the rank and file in the standard 0-based form requires some form of transform to use in both getXY() and str() and is therefore somewhat less-than-optimal. A more optimal way would be to either just store the rank and file as given in init() and then just do the appropriate conversion in getXY(), or convert it to array X-Y coords in init() (which would make getXY() trivial) and do the conversion back to Algebraic Notation in str(). Of those two approaches, we should choose the one that allows for the trivial implementation the most-used of those two methods (getXY() vs. str()). Want me to add a commit with that change?
No description provided.