Skip to content

Fixed bugs in _redoMove() and _undoMove() #15

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

Hengyu
Copy link
Contributor

@Hengyu Hengyu commented Mar 5, 2017

En Passant move

An inconsistency may be created by performing undoMove() and redoMove() several times.

For example: Let a game starts with the following moves: e2->e4, f7->f5, e4->f5.
Then, let's perform undoMove and redoMove. Then check the available moves for black pawn in g7. An inconsistency may be expected.

Reason: In private function _redoMove(), we calls _execute(uncheckedMove: promotion:) and passes the move that will be redone. But the property enPassantMove has not been updated in _redoMove. So there will be an inconsistency in the future calls performed on the game.

Solution: Updates the enPassantMove in _redoMove().

King is checked

kingIsChecked may returns the wrong value.

Reason: This is caused by copying a wrong value to _undoHistory in the function _undoMove().
Solution: Pass the correct value to _undoHistory.append(:).

Hengyu added 2 commits March 5, 2017 22:23
Fixed the bug that a inconsistency may be created by performing
`undoMove()` and `redoMove()` several times.
This bug may cause that `kingIsChecked` returns `false` while actually
it should return `true`.
@Hengyu
Copy link
Contributor Author

Hengyu commented Mar 5, 2017

Wondering
Let's see the property

var _moveHistory: [(move: Move,  piece: Piece, capture: Piece?, enPassantTarget: Square?, kingAttackers: Bitboard, halfmoves: UInt, rights: CastlingRights)]

in file Game.swift.
Does the element in _moveHistory have the following meanings?

  • move: The move that be performed;
  • capure: The piece that this moved captured;
  • enPassantTarge: The En Passant target of the game just before this move is performed;
  • kingAttackers: The king attackers of the game just before this move is performed;
  • halfMoves: Value of halfMoves in the game just before this move is performed;
  • rights: Value of rights in the game just before this move is performed;

@Hengyu Hengyu changed the title Fixed a bug in _redoMove() Fixed bugs in _redoMove() and _undoMove() Mar 6, 2017
werner77 pushed a commit to werner77/Sage that referenced this pull request Nov 23, 2017
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.

1 participant