/// <summary>
        /// Retrieves an element using pure randomness.
        /// </summary>
        /// <typeparam name="T">The type of the elements.</typeparam>
        /// <param name="collection">The set of elements to randomize.</param>
        /// <param name="randomizer">The random index strategy.</param>
        /// <returns>The randomly selected element.</returns>
        public static T GetRandom <T>(this IEnumerable <T> collection, RandomIndex randomizer)
        {
            int n     = collection.Count();
            int index = randomizer(n);

            return(collection.ElementAt(index));
        }
        //한 토너먼트가 끝나면 idPointer를 0으로 리셋시키고, 새로운 토너먼트 id리스트를 받아와야 한다.
        public void UpdateBattleList(int clickOn)
        {
            battles[idPointer - 1].Winner = battles[idPointer - 1].Foods[clickOn];

            //포인터가 리스트의 값을 넘어서서 한 라운드가 끝나면 다음 라운드로 값을 변경시킨다.
            if (idPointer > battles.Count - 1)
            {
                battles[idPointer - 1].Winner = battles[idPointer - 1].Foods[clickOn];

                gameRound /= 2;

                idPointer = 0;

                //각 라운드의 승자가 저장된 Battle List를 넘겨서 다음 대전 리스트를 만든다.
                List <int> winnerList = RandomIndex.ShuffleIndex(battles.ConvertAll(x => x.Winner));

                if (gameRound > 1)
                {
                    //각 라운드의 짝을 묶은 Battle 객체의 리스트를 받는다
                    battles = Battle.GenerateRounds(winnerList);
                }

                //gameRound가 1이 되면(우승이 결정) WinnerForm 창으로 넘어간다
                if (gameRound == 1)
                {
                    WinnerForm winnerForm = new WinnerForm();
                    winnerForm.WinnerIndex = Battle.getWinnerIndex(battles);
                    this.Owner             = winnerForm;
                    formOnOff.HideForm(this);
                    formOnOff.ShowForm(winnerForm);
                }
            }

            UpdateBattleImage(idPointer);
        }
        /// <summary>
        /// Randomly reorders elements in <paramref name="list"/>.
        /// </summary>
        /// <typeparam name="T">The type of the elements.</typeparam>
        /// <param name="list">The set of elements to randomize.</param>
        /// <param name="randomizer">The random index strategy.</param>
        public static void Shuffle <T>(this IList <T> list, RandomIndex randomizer)
        {
            int size = list.Count;

            while (size > 0)
            {
                int index = randomizer(size);
                list.Swap(index, --size);
            }
        }
    private void Start()
    {
        TQ = FindObjectOfType <Test_Questions>();
        TA = FindObjectOfType <Test_Answers>();

        PL = FindObjectOfType <Player_Life>();

        cs = FindObjectOfType <cannon_shoot>();

        RI = FindObjectOfType <RandomIndex>();
    }
 protected static void NotUnderstood(StringBuilder speech)
 {
     speech.Append(GetSpeechPrefix(SpeechPrefix.DYSFLUENCY_NEGATIVE));
     speech.Append(InsertStrengthBreak(StrengthBreak.weak));
     speech.Append(GetSpeechPrefix(SpeechPrefix.APOLOGETIC));
     speech.Append("I misunderstood what you said.");
     speech.Append(InsertStrengthBreak(StrengthBreak.weak));
     speech.Append(SayWithEmotion("Can you say that again?", Emotion.excited, Intensity.low));
     speech.Append(InsertStrengthBreak(StrengthBreak.weak));
     if (!(RandomIndex.NextDouble() > 0.7))
     {
         return;
     }
     speech.Append(SayWithEmotion("Try using the type of media in your request.", Emotion.excited, Intensity.low));
     speech.Append(InsertStrengthBreak(StrengthBreak.weak));
     speech.Append("For example: Use the word \"Movie\" if the item is a movie, or \"Series\" if it is a TV series.");
 }
Beispiel #6
0
        //각 토너먼트가 끌날 때 마다 호출되어서 반환될 리스트를 만든다

        public static List <Battle> GenerateRounds(List <int> list)
        {
            //넘어온 다음 후보 리스트를 섞어준다
            var foodList = RandomIndex.ShuffleIndex(list);

            List <Battle> Battles = new List <Battle>();

            for (int i = 0; i < foodList.Count; i += 2)
            {
                List <int> listItem = new List <int>();
                listItem.Add(foodList[i]);
                listItem.Add(foodList[i + 1]);

                Battles.Add(new Battle {
                    Foods = listItem
                });
            }

            return(Battles);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            //ModeChoiceForm에서 라운드를 가져온다.
            gameRound = GameRound;

            if (gameRound == 16)
            {
                roundImage = (Image)Resources.Round_16;
            }
            else if (gameRound == 8)
            {
                roundImage = (Image)Resources.Round_8;
            }

            pctbRound.Image = roundImage;

            //랜덤으로 음식을 가져올 리스트를 생성해둔다
            foodsList = RandomIndex.GenerateRandIndex(gameRound);

            battles = Battle.GenerateRounds(foodsList);
            UpdateBattleImage(idPointer);
        }
        protected static void ItemBrowse(StringBuilder speech, BaseItem item, IAlexaSession session, bool deviceAvailable = true)
        {
            if (deviceAvailable == false)
            {
                speech.Append(GetSpeechPrefix(SpeechPrefix.DYSFLUENCY_NEGATIVE));
                speech.Append(InsertStrengthBreak(StrengthBreak.weak));
                speech.Append(GetSpeechPrefix(SpeechPrefix.APOLOGETIC));
                speech.Append(InsertStrengthBreak(StrengthBreak.weak));
                speech.Append("That device is currently unavailable.");
                return;
            }

            //speech.Append(GetSpeechPrefix(SpeechPrefix.COMPLIANCE));
            speech.Append(InsertStrengthBreak(StrengthBreak.weak));
            if (RandomIndex.NextDouble() > 0.5 && !item.IsFolder) //Randomly incorporate "Here is.." into phrasing
            {
                speech.Append("Here is ");
            }

            var name = StringNormalization.ValidateSpeechQueryString(item.Name);

            speech.Append(name);

            if (!item.IsFolder) //Don't describe a rating of a library or collection folder.
            {
                var rating = item.OfficialRating;
                speech.Append(", ");
                speech.Append(string.IsNullOrEmpty(rating) ? "unrated" : $"Rated {rating}");
            }

            if (!session.hasRoom)
            {
                return;
            }
            speech.Append(InsertStrengthBreak(StrengthBreak.weak));
            speech.Append("Showing in the ");
            speech.Append(session.room.Name);
        }
Beispiel #9
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: 몇 강을 할지 선택하는 창이 띄운다
            //            ModeChoiceForm modeChoice = new ModeChoiceForm();
            //            modeChoice.Show();

            gameRound = GameRound;
            //몇 강을 할 지 사용자가 선택을 하면 반환값으로 화면을 구성한다.

            if (gameRound == 16)
            {
                roundImage = (Image)Resources.Round_16;
            }
            else if (gameRound == 8)
            {
                roundImage = (Image)Resources.Round_8;
            }

            pctbRound.Image = roundImage;

            //랜덤으로 음식을 가져올 리스트를 생성해둔다
            foodCandidateList = RandomIndex.GenerateRandIndex(gameRound);
            battles           = Battle.GenerateRounds(foodCandidateList);
        }
Beispiel #10
0
        public Quaternion GetRandomAngle()
        {
            RandomIndex<float> xAngle = new RandomIndex<float> ();

            xAngle.AddNewValue(1, 0);
            xAngle.AddNewValue(1, 90);
            xAngle.AddNewValue(1, 180);
            xAngle.AddNewValue(1, 270);

            RandomIndex<float> yAngle = new RandomIndex<float> ();

            yAngle.AddNewValue(1, 0);
            yAngle.AddNewValue(1, 90);
            yAngle.AddNewValue(1, -90);

            float xSelect = xAngle.Select ();
            float ySelect = yAngle.Select ();

            return Quaternion.Euler( xSelect, ySelect, 0);
        }
 /// <summary>
 /// Yields a random sequence of elements.
 /// </summary>
 /// <typeparam name="T">The type of elements.<typeparam>
 /// <param name="collection">The set of elements to randomize.</param>
 /// <param name="options">The parameters of randomization.</param>
 /// <param name="randomizer">The random index strategy.</param>
 /// <returns>The random sequence of elements.</returns>
 public static IEnumerable <T> Randomize <T>(this IEnumerable <T> collection, RandomizationOptions options, RandomIndex randomizer) => Randomize(collection.ToList(), options, randomizer);
        /// <summary>
        /// Yields a random sequence of elements.
        /// </summary>
        /// <typeparam name="T">The type of elements.<typeparam>
        /// <param name="list">The set of elements to randomize.</param>
        /// <param name="options">The parameters of randomization.</param>
        /// <param name="randomizer">The random index strategy.</param>
        /// <returns>The random sequence of elements.</returns>
        public static IEnumerable <T> Randomize <T>(this IList <T> list, RandomizationOptions options, RandomIndex randomizer)
        {
            int n    = list.Count;
            int size = n;

            while (size > 0)
            {
                int index   = randomizer(size);
                T   element = list[index];

                if (options.HasFlag(RandomizationOptions.NoReplacement))
                {
                    size--;
                    Hide(index);
                }
                else
                {
                    if (options.HasFlag(RandomizationOptions.NoConsecutiveValues))
                    {
                        size = n - 1;
                        Hide(index);
                    }
                }

                yield return(element);
            }

            #region PIPELINE
            void Hide(int i) => list.Swap(i, size);

            #endregion
        }
Beispiel #13
0
    // Start is called before the first frame update
    void Start()
    {
        sr = gameObject.GetComponent <SpriteRenderer>();

        RI = FindObjectOfType <RandomIndex>();
    }