Exemplo n.º 1
0
        /// <summary>
        /// Initialize information on the daily trends for food.
        /// </summary>
        public void InitializeDailyTrends()
        {
            // Initialize the string that the trend string will be set to.
            string trendString = "";

            // Get a list of all different types of dishes.
            List <Dish> dishList = this.gameSceneManager.GetAcquiredRecipes().ToList();

            // Initialize likelihoods adding up to 1 indicating how popular the dish will be.
            List <float> foodPopularities = NumberRandomizer.GenerateNFloatsWhoSumToM(dishList.Count, 1f).ToList();

            // Append each dish and its popularity onto the trend string.
            dishPopularityMapping = new Dictionary <Dish, float>();
            for (int index = 0; index < dishList.Count; index++)
            {
                Dish  d = dishList[index];
                float dishPopularity = foodPopularities[index];
                trendString += $"{d.ToTitleCaseSpacedString()}: {dishPopularity * 100:F2}%";

                // Append a newline to the end of the string if we still have more recipe popularities to render.
                if (index < dishList.Count - 1)
                {
                    trendString += "\n";
                }

                // Be sure to keep track of how popular each dish is in a Dictionary.
                dishPopularityMapping[d] = dishPopularity;
            }

            // Finally, set the trend string.
            this.trendingFoodText.text = trendString;
        }
Exemplo n.º 2
0
    /// <summary>
    /// Generate and print a number of floats that sum to the number 1.
    /// </summary>
    private static void GenerateLogFloatsWhoSumToM()
    {
        IEnumerable <float> generateNFloatsWhoSumToM = NumberRandomizer.GenerateNFloatsWhoSumToM(5, 1f);
        string convertToString = generateNFloatsWhoSumToM.AsString();

        Debug.Log(convertToString);
        Debug.Log(generateNFloatsWhoSumToM.Sum());
    }
        public void GetUniqueNumber_idsArrIsFull_ArgumentException()
        {
            //Arrange
            var idsArr    = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var maxNumber = 10;

            //Act

            //Assert
            Assert.Throws <ArgumentException>(() => NumberRandomizer.GetUniqueNumber(idsArr, maxNumber));
        }
        public void GetUniqueNumber_NullIdsArray_NullReferenceException()
        {
            //Arrange
            int[] idsArr    = null;
            var   maxNumber = 999999;

            //Act

            //Assert
            Assert.Throws <NullReferenceException>(() => NumberRandomizer.GetUniqueNumber(idsArr, maxNumber));
        }
Exemplo n.º 5
0
        /// <summary>Given a list interface of items, return a random item from the List.</summary>
        /// <typeparam name="T">The type of the item in <paramref name="listToGetFrom" />.</typeparam>
        /// <param name="listToGetFrom">The list to extract a random item from.</param>
        /// <returns>The randomized item to return from the list.</returns>
        public static T GetRandomItem <T>(this IList <T> listToGetFrom)
        {
            int index = NumberRandomizer.Next(0, listToGetFrom.Count);

            if (listToGetFrom.HasIndex(index))
            {
                return(listToGetFrom[index]);
            }

            throw new IndexOutOfRangeException("We tried to get an item from a list at an index" + "that was" +
                                               "out of range!");
        }
        public void GetUniqueNumber_FreeNumber4_ShouldBe4()
        {
            //Arrange
            var idsArr    = new int[] { 1, 2, 3, 5, 6, 7, 8, 9, 10 };
            var maxNumber = 10;

            var expected = 4;

            //Act
            var actual = NumberRandomizer.GetUniqueNumber(idsArr, maxNumber);

            //Assert
            Assert.Equal(expected, actual);
        }
        public void GetUniqueNumber_NegativeMaxNumber_CorrectExceptionMessage()
        {
            //Arrange
            var idsArr    = new int[] { 1, 2, 3, 5, 6, 7, 8, 9, 10 };
            var maxNumber = -10;

            var expected = "maxNumber cannot be less than zero";

            //Act
            var actual = Record.Exception(() => NumberRandomizer.GetUniqueNumber(idsArr, maxNumber)).Message.Trim();

            //Assert
            Assert.Equal(expected, actual);
        }
        public void GetUniqueNumber_FirstSpinMaxNumber1_ShouldBe1()
        {
            //Arrange
            var idsArr    = new int[] { };
            var maxNumber = 1;

            var expected = 1;

            //Act
            var actual = NumberRandomizer.GetUniqueNumber(idsArr, maxNumber);

            //Assert
            Assert.Equal(expected, actual);
        }
        public void GetUniqueNumber_FreeNumber2Or4and6In10ItemsArray_Return2Or4Or6()
        {
            //Arrange
            var idsArr    = new int[] { 1, 3, 5, 7, 8, 9, 10 };
            var maxNumber = 10;

            var expected = new int[] { 2, 4, 6 };

            //Act
            var actual = NumberRandomizer.GetUniqueNumber(idsArr, maxNumber);

            //Assert
            Assert.Contains(actual, expected);
        }
        public void GetUniqueNumber_FreeNumberLastItemIn999999_Return999999()
        {
            //Arrange
            var idsArr    = Enumerable.Range(1, 999998);
            var maxNumber = 999999;

            var expected = 999999;

            //Act
            var actual = NumberRandomizer.GetUniqueNumber(idsArr, maxNumber);

            //Assert
            Assert.Equal(actual, expected);
        }
        public void GetUniqueNumber_idsArrIsFull_CorrectExceptionMessage()
        {
            //Arrange
            var idsArr    = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var maxNumber = 10;

            var expected = "No free numbers in this range";

            //Act
            var actual = Record.Exception(() => NumberRandomizer.GetUniqueNumber(idsArr, maxNumber)).Message.Trim();

            //Assert
            Assert.Equal(expected, actual);
        }
        public void GetUniqueNumber_NullIdsArray_CorrectExceptionMessage()
        {
            //Arrange
            int[] idsArr    = null;
            var   maxNumber = 999999;

            var expected = "usedNumbers cannot be null";

            //Act
            var actual = Record.Exception(() => NumberRandomizer.GetUniqueNumber(idsArr, maxNumber)).Message.Trim();

            //Assert
            Assert.Equal(expected, actual);
        }
Exemplo n.º 13
0
        /// <summary>Given a List, shuffle and return it.</summary>
        /// <typeparam name="T">The type of object within the given list.</typeparam>
        /// <param name="listToShuffle">The list we are to shuffle before returning.</param>
        /// <returns>The newly shuffled list.</returns>
        public static IList <T> Shuffle <T>(this IList <T> listToShuffle)
        {
            int n = listToShuffle.Count;

            while (n > 1)
            {
                n--;
                int k     = NumberRandomizer.Next(n + 1);
                T   value = listToShuffle[k];
                listToShuffle[k] = listToShuffle[n];
                listToShuffle[n] = value;
            }

            return(listToShuffle);
        }
Exemplo n.º 14
0
        private void CreateGameData(RepositoryFactory repositoryFactory, string gameId)
        {
            using (var transactionManager = repositoryFactory.CreateTransactionManager())
            {
                // Create GameInfo.
                // Overrule the GameInfo Id with the Game Id.
                var gameInfo = new GameInfo
                {
                    Name = DateTime.Now.ToString("yyyyMMddHHmmss"),
                    Id   = gameId
                };

                // Create teams and players.
                var teamsAndPlayers = CreateTeamsAndPlayers(repositoryFactory);

                // ===================================================================
                //TODO OK, let MODDERVOKKIN op
                var numberRandomizer = new NumberRandomizer();
                int randomIndex      = numberRandomizer.GetNumber(0, Constants.HowManyTeamsPerLeague * Constants.HowManyLeagues - 1);
                gameInfo.CurrentTeam = teamsAndPlayers.Teams[randomIndex];
                // ===================================================================

                transactionManager.RegisterInsert(gameInfo);

                // Insert teams.
                transactionManager.RegisterInsert(teamsAndPlayers.Teams);

                // Insert players.
                transactionManager.RegisterInsert(teamsAndPlayers.Players);

                // Create a season with match schedules.
                var seasonManager = new SeasonManager(repositoryFactory, gameInfo.CurrentTeam);
                seasonManager.CreateFirstSeason(teamsAndPlayers.Teams, transactionManager);

                transactionManager.Save();
            }
        }
Exemplo n.º 15
0
 public PlayerManager()
 {
     _numberRandomizer = new NumberRandomizer();
     _playerGenerator  = new PlayerGenerator();
 }
Exemplo n.º 16
0
 /// <summary>Given a HashSet of items, return a random item from the List.</summary>
 /// <param name="lst">The list to extract a random item from.</param>
 /// <typeparam name="T">The type of the item in the <paramref name="lst" />.</typeparam>
 /// <returns>The item of type <see cref="T" /> returned by the randomizer.</returns>
 public static T GetRandomItem <T>(this HashSet <T> lst)
 {
     return(lst.ToList()[NumberRandomizer.Next(0, lst.Count)]);
 }
Exemplo n.º 17
0
 /// <summary>Given an ArrayList of items, return a random item from the List.</summary>
 /// <typeparam name="T">The type of item in the list <paramref name="lst" />.</typeparam>
 /// <param name="lst">The list to extract a random item from.</param>
 /// <returns>A random item of type <see cref="T" /> from the list.</returns>
 public static T GetRandomItem <T>(this ArrayList lst)
 {
     return((T)lst[NumberRandomizer.Next(0, lst.Count)]);
 }
Exemplo n.º 18
0
 /// <summary>Given an array of items, return a random item from the List.</summary>
 /// <typeparam name="T">The type of item in the array <paramref name="lst" />.</typeparam>
 /// <param name="lst">The list to extract a random item from.</param>
 /// <returns>The randomized item of type <see cref="T" /> to return from the array.</returns>
 public static T GetRandomItem <T>(this T[] lst)
 {
     return(lst[NumberRandomizer.Next(0, lst.Length)]);
 }
Exemplo n.º 19
0
 /// <summary>Given an Array of items, return a random item from the List.</summary>
 /// <typeparam name="T">The type of item in the given <paramref name="lst" />.</typeparam>
 /// <param name="lst">The list to get a random item from.</param>
 /// <returns>The random item as returned from <paramref name="lst" />.</returns>
 public static T GetRandomItem <T>(this Array lst)
 {
     return((T)lst.GetValue(NumberRandomizer.Next(0, lst.Length)));
 }