Open Hengyu opened 7 years ago
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?
halfMoves
in the game just before this move is performed;rights
in the game just before this move is performed;
En Passant move
An inconsistency may be created by performing
undoMove()
andredoMove()
several times.For example: Let a game starts with the following moves: e2->e4, f7->f5, e4->f5. Then, let's perform
undoMove
andredoMove
. 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 propertyenPassantMove
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(:)
.