Esempio n. 1
0
        public void RandomPop_WithEmptySpan_Throws()
        {
            int[] array = new int[0];

            Assert.Throws <IndexOutOfRangeException>(
                () => Spans.PopRandom(new Random(), new Span <int>(array)));
        }
Esempio n. 2
0
        public void RandomPop_WithOneValue_ReturnsValueAndLeavesUnchanged()
        {
            Span <int> span = stackalloc int[1];

            span[0] = 5;

            Assert.Equal(5, Spans.PopRandom(new Random(), span));
            Assert.Equal(5, span[0]);
        }
Esempio n. 3
0
        public void RandomPop_WithManyValues_ReturnsValueAndSwapsValueToEnd()
        {
            Span <int> span = stackalloc int[5] {
                0, 1, 2, 3, 4
            };

            Assert.Equal(1, Spans.PopRandom(new Random(1234), span));
            Assert.Equal(new int[5] {
                0, 4, 2, 3, 1
            }, span.ToArray());
        }
Esempio n. 4
0
        private static bool _TrySolveRandomly(Guesser <TPuzzle> guesser, Random rand)
        {
            if (guesser.IsSolved)
            {
                return(true);
            }
            Span <Guess> guesses    = stackalloc Guess[guesser.MaxGuessCount];
            var          guessCount = guesser.PopulateBestGuesses(guesses);

            while (guessCount > 0)
            {
                ref Guess guess = ref Spans.PopRandom(rand, guesses[0..guessCount--]);
Esempio n. 5
0
        private bool _TrySolveRandomly(SquareTracker <TPuzzle> tracker, Random random)
        {
            if (tracker.Puzzle.NumEmptySquares == 0)
            {
                return(true);
            }
            Coordinate c = tracker.GetBestCoordinateToGuess();
            Span <int> possibleValues = stackalloc int[tracker.Puzzle.Size];
            int        numPossible    = tracker.PopulatePossibleValues(in c, possibleValues);

            while (numPossible > 0)
            {
                int possibleValue = Spans.PopRandom(random, possibleValues[0..numPossible--]);