Skip to content
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

Fix problems of promotions #13

Closed
wants to merge 1 commit into from
Closed

Conversation

mathjudo
Copy link

@mathjudo mathjudo commented Dec 30, 2017

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

@ddugovic
Copy link
Contributor

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

@mathjudo
Copy link
Author

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
Copy link
Author

mathjudo commented Dec 31, 2017

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'

@ddugovic
Copy link
Contributor

ddugovic commented Dec 31, 2017

@mathjudo I attempted the same change db9d95b 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'

@mathjudo
Copy link
Author

mathjudo commented Jan 1, 2018

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)

@ddugovic
Copy link
Contributor

ddugovic commented Jan 1, 2018

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
Copy link
Contributor

ddugovic commented Jan 7, 2018

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

@marcusbuffett
Copy link
Owner

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

@ClasherKasten
Copy link
Collaborator

ClasherKasten commented Sep 21, 2022

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 db9d95b and 83b8869

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants