Exemplo n.º 1
0
        public void Should_randomize_same_way_with_same_seed_value()
        {
            var list = Enumerable.Range(0, 50).Select(x => x).ToList();

            list.ForEach(i =>
            {
                var seed            = new SeedInstance(123, i);
                var listRandomizer1 = new ListRandomizer <int>(seed, list);
                var listRandomizer2 = new ListRandomizer <int>(seed, list);

                listRandomizer1.GetTodaysItem().Should().Be(listRandomizer2.GetTodaysItem());
            });
        }
Exemplo n.º 2
0
        public void Random_should_be_outside_rollover_index_range()
        {
            var list = Enumerable.Range(0, 50).Select(x => x).ToList();

            var firstN = new List <int>();

            // get first N days
            for (var i = 0; i < SeedGenerator.DaysPerSeed; i++)
            {
                var seed     = new SeedInstance(345, i);
                var listRand = new ListRandomizer <int>(seed, list);
                firstN.Add(listRand.GetTodaysItem());
            }

            var listRandomizer = new ListRandomizer <int>(new SeedInstance(345, 0), list);

            for (var i = 0; i < list.Count - SeedGenerator.DaysPerSeed; i++)
            {
                firstN.Should().NotContain(listRandomizer.GetRandomItemOutsideRolloverScope());
            }
        }
    /// <summary>
    /// Manage how functions are placed in the buttons of the level
    /// </summary>
    public void ManageFunctions()
    {
        // Reset winning conditions
        isPanel_Open       = false;
        isPressureReleased = false;
        isDoorOpen         = false;


        // Reset button list
        List <HoverButton> listButtons = buttonHolder.GetComponentsInChildren <HoverButton>().ToList();

        // List of methods to be called by the in-game panels
        List <UnityAction <Hand> > listActions = new List <UnityAction <Hand> > {
            DropSpheres,
            SparkTheButton,
            DropConfetti,
            PlayButtonSound,
            PlayDisasterAnimation1,
            PlayDisasterAnimation2,
            PlayDisasterAnimation3,
            PlayDisasterAnimation4,
            //PlayDisasterAnimation,
            //PlayDisasterAnimation,
            //PlayDisasterAnimation,
            //PlayDisasterAnimation,
            AnimateWall,
            PlayButtonSound,
            OpenPanel,
            ReleasePressure,
            OpenDoors
        };

        // Randomize the methods
        ListRandomizer.Randomize(ref listActions);

        // Populate the buttons with the methods
        PopulateButtons(ref listButtons, ref listActions);
    }
        private List <Annotations> GoGenerateImages(List <IGrouping <string, Annotations> > imagesWithNoCars, List <IGrouping <string, Annotations> > imagesWithLotsOfCars)
        {
            var allAnnotations = new List <Annotations>();

            var outputAnnotationsDir = Path.GetDirectoryName(_outputAnnotationsFile);

            var imagesWithNoCarsRandomizedOrder     = ListRandomizer.Shuffle(imagesWithNoCars, 42);
            var imagesWithLotsOfCarsRandomizedorder = ListRandomizer.Shuffle(imagesWithLotsOfCars, 4242);

            int minOfBoth = Math.Min(imagesWithNoCarsRandomizedOrder.Count, imagesWithLotsOfCarsRandomizedorder.Count);
            int maxOfBoth = Math.Max(imagesWithNoCarsRandomizedOrder.Count, imagesWithLotsOfCarsRandomizedorder.Count);

            for (int i = 0; i < maxOfBoth; i++)
            {
                var iNoCars     = i % imagesWithNoCarsRandomizedOrder.Count;
                var iLotsOfCars = i % imagesWithLotsOfCarsRandomizedorder.Count;

                var noCarImageTags     = imagesWithNoCarsRandomizedOrder[iNoCars];
                var lotsOfCarImageTags = imagesWithLotsOfCarsRandomizedorder[iLotsOfCars];

                var imagePathNoCars         = Path.Combine(_dirOfAnnotationsFile, noCarImageTags.Key);
                var imagePathNoCarsResolved = PathHelper.EscapePathCorrectly(Path.GetFullPath(imagePathNoCars));

                var imagePathLotsOfCars         = Path.Combine(_dirOfAnnotationsFile, lotsOfCarImageTags.Key);
                var imagePathLotsOfCarsResolved = PathHelper.EscapePathCorrectly(Path.GetFullPath(imagePathLotsOfCars));

                using (var imageNoCars = Image.Load(imagePathNoCarsResolved))
                {
                    using (var imageWithCars = Image.Load(imagePathLotsOfCarsResolved))
                    {
                        foreach (var carImageTags in lotsOfCarImageTags)
                        {
                            var rectangle = SpatialHelper.BoxToRectangle(carImageTags.X1.Value, carImageTags.Y1.Value, carImageTags.X2.Value, carImageTags.Y2.Value);

                            var cloneOfImageWithCars = imageWithCars.Clone();
                            cloneOfImageWithCars.Mutate(t => t.Crop(rectangle));

                            imageNoCars.Mutate(t => t.DrawImage(cloneOfImageWithCars, new Point(rectangle.X, rectangle.Y), GraphicsOptions.Default));
                        }
                    }

                    var outFileName = $"Generated_{i}.jpg";
                    var outPath     = Path.Combine(_outputDirImages, outFileName);
                    using (var outStream = new FileStream(outPath, FileMode.Create, FileAccess.Write, FileShare.Read))
                    {
                        Console.WriteLine($"\tStoring: {outFileName}");
                        imageNoCars.SaveAsJpeg(outStream);
                    }

                    foreach (var existingTag in lotsOfCarImageTags)
                    {
                        var newTag = new Annotations()
                        {
                            Tag       = existingTag.Tag,
                            ImagePath = PathHelper.EscapePathCorrectly(Path.GetRelativePath(outputAnnotationsDir, outPath)),
                            X1        = existingTag.X1,
                            X2        = existingTag.X2,
                            Y1        = existingTag.Y1,
                            Y2        = existingTag.Y2
                        };

                        allAnnotations.Add(newTag);
                    }
                }
            }

            return(allAnnotations);
        }
Exemplo n.º 5
0
        private PlayerProfile GetRandomPlayerProfile(IEnumerable <PlayerProfile> playerProfiles)
        {
            var randomPlayerProfile = ListRandomizer.GetItem(playerProfiles);

            return(randomPlayerProfile);
        }
Exemplo n.º 6
0
 public TeamManager(RepositoryFactory repositoryFactory)
 {
     _repositoryFactory = repositoryFactory;
     _listRandomizer    = new ListRandomizer();
 }