Example #1
0
        private static void TestShuffleAlgorithm(IShuffleAlgorithm algo, bool forward)
        {
            for (int i = 1; i < 1000; i++)
            {
                var checkNumbers = new BitArray(i, false);

                algo.Length = i;
                algo.Seed   = i;

                for (int j = 0; j < i; j++)
                {
                    if (forward)
                    {
                        algo.Next();
                    }
                    else
                    {
                        algo.Prev();
                    }
                    int shufNum = algo.Index;
                    if (checkNumbers.Get(shufNum))
                    {
                        Assert.Fail("Duplicate number");
                    }
                    checkNumbers.Set(shufNum, true);
                }
            }
        }
Example #2
0
 internal PlaylistManager(PlaylistManagerData pmd)
 {
     data      = pmd;
     json      = new JavaScriptSerializer();
     shuffle   = new ListedShuffle();
     dataSets  = new List <DataSet>();
     playQueue = new Queue <PlayData>();
 }
		internal PlaylistManager(PlaylistManagerData pmd)
		{
			data = pmd;
			json = new JavaScriptSerializer();
			shuffle = new ListedShuffle();
			dataSets = new List<DataSet>();
			playQueue = new Queue<PlayData>();
		}
 public Question(IShuffleAlgorithm shuffleAlgorithm, string text, string correctAnswer, IEnumerable <string> falseAnswers)
 {
     Text = text;
     _shuffleAlgorithm = shuffleAlgorithm;
     _correctAnswer    = correctAnswer;
     _falseAnswers     = falseAnswers;
     _shuffledAnswers  = new Lazy <IEnumerable <string> >(() => ShuffleAnswers());
 }
Example #5
0
        // Playlistfactory related stuff

        public PlaylistManager(PlaylistManagerData pmd)
        {
            data    = pmd;
            shuffle = new LinearFeedbackShiftRegister {
                Seed = Util.Random.Next()
            };
            freeList  = new Playlist(string.Empty);
            trashList = new Playlist(string.Empty);
        }
Example #6
0
 /// <summary>
 /// Initialize a full deck of cards
 /// </summary>
 /// <param name="aceHigh">indicate whether the game plays Ace High or Ace Low (default: Ace Low)</param>
 /// <param name="shuffleAlgorithm">Use a specialized shuffle algorithm.  (default:  RifleShuffler)</param>
 public Deck(bool aceHigh = false, IShuffleAlgorithm shuffleAlgorithm = null)
 {
     // the default shuffle algorithm is RifleShuffle.
     if (shuffleAlgorithm == null)
     {
         myShuffler = new RiffleShuffler();
     }
     else
     {
         myShuffler = shuffleAlgorithm;
     }
     TheDeck = new List <Card>();
     foreach (Card.Suit suit in Card.Suit.Suits)
     {
         // what the F(^!*$ is going on in this line................. what is the `?` doing there....
         foreach (Card.Value value in (aceHigh ? Card.Value.AcesHighValues : Card.Value.AcesLowValues))
         {
             TheDeck.Add(new Card(suit, value));
         }
     }
 }
 public PractiseInitializerFactory(IConsumer consumer, IShuffleAlgorithm shuffleAlgorithm)
 {
     _consumer         = consumer;
     _shuffleAlgorithm = shuffleAlgorithm;
 }
 public Practise(IShuffleAlgorithm shuffleAlgorithm, IVocabulary vocabulary)
 {
     _shuffleAlgorithm = shuffleAlgorithm;
     _vocabulary       = vocabulary;
     _answers          = new Dictionary <IQuestion, string>();
 }
 public PractiseInitializer(IApplicationInitializer applicationInitializer, IConsumer consumer, IShuffleAlgorithm shuffleAlgorithm)
 {
     _applicationInitializer = applicationInitializer;
     _consumer         = consumer;
     _shuffleAlgorithm = shuffleAlgorithm;
 }
Example #10
0
 private static void TestShuffleAlgorithmBiDir(IShuffleAlgorithm algo)
 {
     TestShuffleAlgorithm(algo, true);
     TestShuffleAlgorithm(algo, false);
 }
Example #11
0
        public static IEnumerable <T> Shuffle <T>(this IEnumerable <T> items, IShuffleAlgorithm shuffleAlgorithm)
        {
            var shuffledItems = shuffleAlgorithm.Shuffle(items);

            return(shuffledItems);
        }
 protected Shuffler()
 {
     _defaultAlgorithm = new FisherYatesAlgorithm();
 }
 public virtual IEnumerable <T> Shuffle <T>(IEnumerable <T> collection, IShuffleAlgorithm algorithm)
 {
     return(algorithm.Shuffle(collection));
 }
 protected Shuffler(IShuffleAlgorithm algorithm)
 {
     _defaultAlgorithm = algorithm;
 }
 public DefaultShuffler(IShuffleAlgorithm algorithm) : base(algorithm)
 {
 }