Skip to content

Commit

Permalink
chess:feature auto-promote to queen
Browse files Browse the repository at this point in the history
  • Loading branch information
wkta committed Aug 2, 2023
1 parent 481fb9f commit 7eeb8e9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions examples/chess/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,23 @@ def move_piece(self, mv_tuple):
en_passant = False
messageString = 'ERR.'

if self._prev_source_piece == 'w'+C_PAWN:
if toSquare_r == 0:
# auto-promote to queen
self.squares[fromSquare_r][fromSquare_c] = C_EMPTY_SQUARE # square left
self.squares[toSquare_r][toSquare_c] = colorsym(self.curr_player)+'Q'
self._play_sequence += 1
return "White pawn moves from " + coords_to_alg(mv_tuple[0]) + \
" to " + coords_to_alg(mv_tuple[1]) + ", gets promoted"
if self._prev_source_piece == 'b'+C_PAWN:
if toSquare_r == 7:
# auto-promote to queen
self.squares[fromSquare_r][fromSquare_c] = C_EMPTY_SQUARE # square left
self.squares[toSquare_r][toSquare_c] = colorsym(self.curr_player)+'Q'
self._play_sequence += 1
return "Black pawn moves from " + coords_to_alg(mv_tuple[0]) + \
" to " + coords_to_alg(mv_tuple[1]) + ", gets promoted"

if self.pawn_jumped:
if toSquare_r == self.jumped_over[0] and toSquare_c == self.jumped_over[1]:
en_passant = True
Expand Down

0 comments on commit 7eeb8e9

Please sign in to comment.