command-line-chess icon indicating copy to clipboard operation
command-line-chess copied to clipboard

Fix problems of promotions

Open mathjudo opened this issue 6 years ago • 8 comments

Hello everyone, There were some problems of promotion when pawns had to be promoted when they took. Sorry I don't find how to open correctly a pull request (with correct comparaisons) so I jus put modified files here. Changes are in methods undoLastMove and makeMove of Board and in line 74 of Pawn Have a nice day

mathjudo avatar Dec 30 '17 15:12 mathjudo

Can you comment in this comment section about how to duplicate the problem and how to fix it?

ddugovic avatar Dec 30 '17 23:12 ddugovic

An error is raised when a Pawn can take another piece in the last line ( line 8 for whites, 1 for blacks ) because it have to be promoted in the same time. Indeed the possibility of promotion when a pawn takes another piece had an error. To fix it we have to modify methods undoLastMove and makeMove of Board.py and to modify the move yielded by the Pawn when it takes on the last line. like in files I uploaded above. Sorry for my English, but if you need more precisions don't hesitate to ask me

mathjudo avatar Dec 31 '17 16:12 mathjudo

For instance :

8  R . . . . . . .  
7  . p . . K . . .  
6  . . . . . . . .  
5  . . . . . . . .  
4  . . . . . . . .  
3  . . . . . . K .  
2  . . . . . . . .  
1  . . . . . . . .  
                     
   a b c d e f g h

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/mathjudo/Downloads/command-line-chess-master-2/build/lib/chess/main.py", line 139, in main
    startGame(board, playerSide, opponentAI)
  File "/Users/mathjudo/Downloads/command-line-chess-master-2/build/lib/chess/main.py", line 88, in startGame
    if board.isCheckmate():
  File "/Users/mathjudo/Downloads/command-line-chess-master-2/build/lib/chess/Board.py", line 114, in isCheckmate
    if len(self.getAllMovesLegal(self.currentSide)) == 0:
  File "/Users/mathjudo/Downloads/command-line-chess-master-2/build/lib/chess/Board.py", line 400, in getAllMovesLegal
    if self.moveIsLegal(move):
  File "/Users/mathjudo/Downloads/command-line-chess-master-2/build/lib/chess/Board.py", line 392, in moveIsLegal
    self.undoLastMove()
  File "/Users/mathjudo/Downloads/command-line-chess-master-2/build/lib/chess/Board.py", line 91, in undoLastMove
    self.pieces.remove(promotedPiece)
  File "/Users/mathjudo/Downloads/command-line-chess-master-2/build/lib/chess/Piece.py", line 40, in __eq__
    if self.board == other.board and \
AttributeError: 'NoneType' object has no attribute 'board'

mathjudo avatar Dec 31 '17 16:12 mathjudo

@mathjudo I attempted the same change db9d95ba9bd40c0c53db9bec6c35046ef3286d30 you made, but it doesn't work (White pawn on a7)?

8  R N B Q K B N R
7  P P P P P P P P
6  
5  
4  
3  
2  P P P P P P P P
1  R N B Q K B N R
                     
   a b c d e f g h

Traceback (most recent call last):
  File "src/main.py", line 130, in <module>
    startGame(board, playerSide, opponentAI)
  File "src/main.py", line 78, in startGame
    if board.isCheckmate():
  File "/home/lila/command-line-chess/src/Board.py", line 132, in isCheckmate
    if len(self.getAllMovesLegal(self.currentSide)) == 0:
  File "/home/lila/command-line-chess/src/Board.py", line 458, in getAllMovesLegal
    if self.moveIsLegal(move):
  File "/home/lila/command-line-chess/src/Board.py", line 450, in moveIsLegal
    self.undoLastMove()
  File "/home/lila/command-line-chess/src/Board.py", line 103, in undoLastMove
    self.pieces.remove(promotedPiece)
  File "/home/lila/command-line-chess/src/Piece.py", line 41, in __eq__
    if self.board == other.board and \
AttributeError: 'NoneType' object has no attribute 'board'

ddugovic avatar Dec 31 '17 18:12 ddugovic

Did you also modified the Pawn.py file as I sent ? (Replace line 74 move = Move(self, newPosition) by move = Move(self, newPosition, pieceToCapture=pieceToTake) and why did you modifie the method makeStringRep ? (line 183)

mathjudo avatar Jan 01 '18 15:01 mathjudo

Thanks, I missed that line 74.

I modified makeStringRep to revert a previous formatting change which caused the 8th rank to display without left-padding spaces.

ddugovic avatar Jan 01 '18 16:01 ddugovic

@mathjudo Please try latest master and advise if you're still observing this issue. Thanks!

ddugovic avatar Jan 07 '18 08:01 ddugovic

Coming in just over a year late on this one! This diff looks odd though, @mathjudo should this go in or no? I haven't really been paying much attention to this project, as you can tell

marcusbuffett avatar Dec 17 '19 03:12 marcusbuffett

Closed for the following reasons:

  • It got opened 7 years ago, most of the code seems outdated
  • The fix is made in completely new files which aren't related to the project at all (weird diff like @marcusbuffett mentioned)
  • It already seems to get fixed by @ddugovic through db9d95ba9bd40c0c53db9bec6c35046ef3286d30 and 83b88698df071268ca3430c3dfb071e7246e2735

If anyone still has problems with this, please leave a comment so the community can discuss about it.

ClasherKasten avatar Sep 21 '22 15:09 ClasherKasten