From 1f124cd1406dad85d1b51142aebca200c327bd95 Mon Sep 17 00:00:00 2001 From: zachartrand <80857317+zachartrand@users.noreply.github.com> Date: Fri, 19 Mar 2021 20:16:29 -0400 Subject: [PATCH] Updated main and engine files Bug fixes. --- chess_engine.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/chess_engine.py b/chess_engine.py index ae3c11c..3badb3c 100644 --- a/chess_engine.py +++ b/chess_engine.py @@ -127,7 +127,7 @@ def undo_move(self): self.board.update_pieces() # For debugging. - print('Undid {}.'.format(move.get_chess_notation()), end=' ') + print('Undid {}'.format(move.get_chess_notation()), end=' ') def redo_move(self): '''Redo a previously undone move.''' @@ -349,12 +349,17 @@ def get_pawn_moves(self, pawn, moves): if self.enpassant and r == enpassantRank: for x, _ in DIRECTIONS['HORIZONTAL']: - sideSquare = s[f + x, r] + sideSquare = s[f+x, r] piece = sideSquare.get_piece() if piece != None: - if (piece.get_name() == 'Pawn' - and piece.get_first_move().end_square == sideSquare): - endSquare = s[f + x, r + y] + moveNumber = piece.first_move.move_number + if (piece.get_name() == 'Pawn' + and piece.get_first_move().end_square == sideSquare + and ((self.white_to_move + and self.move_number - 1 == moveNumber) + or (not self.white_to_move + and self.move_number == moveNumber))): + endSquare = s[f+x, r+y] moves.append(Move( startSquare, endSquare, self.move_number, enpassantSquare=sideSquare @@ -374,7 +379,7 @@ def get_knight_moves(self, knight, moves): f, r = knight.get_coords() s = self.board.squares for x, y in knight.get_directions(): - endFile, endRank = f + x, r + y + endFile, endRank = f+x, r+y if ( (0 <= endFile < self.file_size) and (0 <= endRank < self.rank_size) @@ -406,7 +411,7 @@ def find_moves_on_path(self, piece, moves): or piece.get_pin_direction() == direction or piece.get_pin_direction() == (-x, -y)): for i in range(1, pathRange): - file, rank = f + x * i, r + y * i + file, rank = f + x*i, r + y*i if (0 <= file < self.file_size and 0 <= rank < self.rank_size): path_square = self.board.squares[file, rank] @@ -455,7 +460,7 @@ def get_pins_and_checks(self, king, king_end_square=None): possiblePin = () # Reset possible pins for i, j in zip(range(1, self.file_size), range(1, self.rank_size)): - (endFile, endRank) = (kingFile + x * i, kingRank + y * j) + (endFile, endRank) = (kingFile + x*i, kingRank + y*j) if ((0 <= endFile < self.file_size) and (0 <= endRank < self.rank_size)): square = self.board.squares[endFile, endRank] @@ -637,8 +642,12 @@ def get_chess_notation(self): number = str(self.move_number + 1) + '. ' if self.piece_moved.get_name() == 'Pawn': - startFile, promoSymbol = '', '' - if self.piece_captured != None: + startFile, promoSymbol, ep = '', '', '' + if self.contains_enpassant(): + startFile = startSquare[0] + ep = 'e.p.' + spacer = 'x' + elif self.piece_captured != None: startFile = startSquare[0] spacer = 'x' if self.contains_promotion(): @@ -650,6 +659,7 @@ def get_chess_notation(self): spacer, endSquare, promoSymbol, + ep, ]) else: