Example #1
0
        /// <summary>
        /// Makes a chess move in the data structure
        /// </summary>
        /// <param name="move">The move to make</param>
        /// <returns>true if everything was fine, false if unable to progress - fx castleling position under attack</returns>
        public bool MakeMove(Move move)
        {
            if (!Position.MakeMove(move))
            {
                return(false);
            }

            // advances the position
            var previous = _stateList[PositionIndex++];

            State               = Position.State = _stateList[PositionIndex];
            State.SideToMove    = ~previous.SideToMove;
            State.Material      = previous.Material;
            State.HalfMoveCount = PositionIndex;
            State.LastMove      = move;

            // compute in-check
            Position.InCheck       = Position.IsAttacked(Position.GetPieceSquare(EPieceType.King, State.SideToMove), ~State.SideToMove);
            State.CastlelingRights = _stateList[PositionIndex - 1].CastlelingRights & _castleRightsMask[move.GetFromSquare().AsInt()] & _castleRightsMask[move.GetToSquare().AsInt()];
            State.NullMovesInRow   = 0;

            // compute reversible half move count
            State.ReversibleHalfMoveCount = move.IsCaptureMove() || move.GetMovingPieceType() == EPieceType.Pawn
                ? 0
                : previous.ReversibleHalfMoveCount + 1;

            // compute en-passant if present
            State.EnPassantSquare = move.IsDoublePush()
                ? move.GetFromSquare() + move.GetMovingSide().PawnPushDistance()
                : ESquare.none;

            State.Key = previous.Key;
            State.PawnStructureKey = previous.PawnStructureKey;

            UpdateKey(move);
            State.Material.MakeMove(move);

            //State.GenerateMoves();

            return(true);
        }