Skip to content

Commit

Permalink
Updated main and engine files
Browse files Browse the repository at this point in the history
Bug fixes.
  • Loading branch information
zachartrand committed Mar 20, 2021
1 parent a5f0e49 commit 1f124cd
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions chess_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.'''
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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():
Expand All @@ -650,6 +659,7 @@ def get_chess_notation(self):
spacer,
endSquare,
promoSymbol,
ep,
])

else:
Expand Down

0 comments on commit 1f124cd

Please sign in to comment.