Пример #1
0
        public void RecordCutOffMove(
            [NotNull] GameBoard board,
            [NotNull] GameMove move,
            int plyDistance,
            int remainingDepth,
            [CanBeNull] ICollection <GameMove> previousQuietMoves)
        {
            if (board is null)
            {
                throw new ArgumentNullException(nameof(board));
            }

            if (move is null)
            {
                throw new ArgumentNullException(nameof(move));
            }

            if (plyDistance < MinDepth || plyDistance > MaxDepth)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(plyDistance),
                          plyDistance,
                          $@"The value is out of the valid range ({MinDepth} .. {MaxDepth}).");
            }

            if (board.State.IsAnyCheck() || remainingDepth <= 0)
            {
                return;
            }

            if (!board.ValidMoves.TryGetValue(move, out var moveFlags) || !LocalHelper.IsQuietMove(moveFlags))
            {
                return;
            }

            var moveBonus = remainingDepth.Sqr();

            lock (_syncLock)
            {
                _killerMoveDatas[plyDistance - 1].RecordKiller(move);

                UpdateHistoryTableUnsafe(board, move, moveBonus);

                if (previousQuietMoves is null || previousQuietMoves.Count == 0)
                {
                    return;
                }

                foreach (var previousQuietMove in previousQuietMoves)
                {
                    UpdateHistoryTableUnsafe(board, previousQuietMove, -moveBonus);
                }
            }
        }
Пример #2
0
        private static void AddSingleKillerMove(
            [CanBeNull] GameMove killerMove,
            [NotNull] Dictionary <GameMove, GameMoveFlags> remainingMoves,
            [NotNull] List <OrderedMove> resultList)
        {
            if (killerMove is null || !remainingMoves.TryGetValue(killerMove, out var moveFlags) ||
                !LocalHelper.IsQuietMove(moveFlags))
            {
                return;
            }

            var orderedMove = new OrderedMove(killerMove, moveFlags);

            resultList.Add(orderedMove);
            remainingMoves.Remove(killerMove);
        }