internal void UndoMove(Move.Move move, Player player) { MovePiece(move.DestSquare, move.OriginSquare); if (move.IsCapture) { var capturedPieceSquare = GetCapturedPieceSquare(move); var pieceToRessurect = new PieceOnBoard( Utils.GetOtherPlayer(player), move.GetCapturedPiece(), capturedPieceSquare); _pieceTable.InsertPiece(pieceToRessurect); _occupiedSquares.SetBit(capturedPieceSquare.IntValue); } if (move.IsPromotion) { _pieceTable.UpdatePiece(move.OriginSquare.IntValue, Piece.Pawn); } else if (move.IsShortCastle) { UndoMove(GetShortCastleRookMove(player), player); } else if (move.IsLongCastle) { UndoMove(GetLongCastleRookMove(player), player); } }
public void InsertPiece(PieceOnBoard pieceOnBoard) { var linkedList = _playerPieces[(int)pieceOnBoard.player]; var squareIndex = pieceOnBoard.square.IntValue; if (pieceOnBoard.piece == Piece.King) { _table[squareIndex] = linkedList.AddFirst(pieceOnBoard); } else { _table[squareIndex] = linkedList.AddLast(pieceOnBoard); } }