Exemple #1
0
 public SelectionParameters(SelectionSeverity severity, int nRequired = 0, bool getMaxData = false, bool useJourney = true, PackListHistory packListHistory = PackListHistory.NoFilter, List <string> filteringIds = null)
 {
     this.nRequired       = nRequired;
     this.getMaxData      = getMaxData;
     this.severity        = severity;
     this.useJourney      = useJourney;
     this.packListHistory = packListHistory;
     this.filteringIds    = filteringIds;
 }
 public SelectionParameters(SelectionSeverity severity, int nRequired = 0, bool getMaxData = false, bool useJourney = true, JourneyFilter journeyFilter = JourneyFilter.CurrentJourney, PackListHistory packListHistory = PackListHistory.NoFilter, List <string> filteringIds = null, bool sortDataByDifficulty = false)
 {
     this.nRequired            = nRequired;
     this.getMaxData           = getMaxData;
     this.severity             = severity;
     this.useJourney           = useJourney;
     this.journeyFilter        = journeyFilter;
     this.packListHistory      = packListHistory;
     this.filteringIds         = filteringIds;
     this.sortDataByDifficulty = sortDataByDifficulty;
 }
Exemple #3
0
 public QuestionBuilderParameters()
 {
     this.correctChoicesHistory = PackListHistory.RepeatWhenFull;
     this.wrongChoicesHistory   = PackListHistory.RepeatWhenFull;
     this.useJourneyForCorrect  = true;
     this.useJourneyForWrong    = false;
     this.correctSeverity       = SelectionSeverity.MayRepeatIfNotEnough;
     this.wrongSeverity         = SelectionSeverity.MayRepeatIfNotEnough;
     this.letterFilters         = new LetterFilters();
     this.wordFilters           = new WordFilters();
     this.phraseFilters         = new PhraseFilters();
 }
 public QuestionBuilderParameters()
 {
     this.correctChoicesHistory    = PackListHistory.RepeatWhenFull;
     this.wrongChoicesHistory      = PackListHistory.RepeatWhenFull;
     this.useJourneyForCorrect     = true;
     this.useJourneyForWrong       = true;
     this.correctSeverity          = SelectionSeverity.MayRepeatIfNotEnough;
     this.wrongSeverity            = SelectionSeverity.MayRepeatIfNotEnough;
     this.letterEqualityStrictness = LetterEqualityStrictness.LetterOnly;
     this.letterFilters            = new LetterFilters();
     this.wordFilters           = new WordFilters();
     this.phraseFilters         = new PhraseFilters();
     this.sortPacksByDifficulty = true;
 }
Exemple #5
0
        public List <T> SelectData <T>(System.Func <List <T> > builderSelectionFunction, SelectionParameters selectionParams) where T : IData
        {
            // skip if we require 0 values
            if (selectionParams.nRequired == 0 && !selectionParams.getMaxData)
            {
                return(new List <T>());
            }

            string debugString = "";

            //debugString += "--------- TEACHER: data selection --------- ";

            // @note: not the best of solutions, but I do not seem to be able to get more generic than this without rewriting most stuff.
            System.Type typeParameterType = typeof(T);
            HashSet <T> journeyData       = null;
            HashSet <T> currentPSData     = null;
            DbTables    table             = DbTables.Letters;

            if (typeParameterType == typeof(LetterData))
            {
                table         = DbTables.Letters;
                journeyData   = new HashSet <T>(journeyLetters.Cast <T>());
                currentPSData = new HashSet <T>(currentPlaySessionLetters.Cast <T>());
            }
            else if (typeParameterType == typeof(WordData))
            {
                table         = DbTables.Words;
                journeyData   = new HashSet <T>(journeyWords.Cast <T>());
                currentPSData = new HashSet <T>(currentPlaySessionWords.Cast <T>());
            }
            else if (typeParameterType == typeof(PhraseData))
            {
                table         = DbTables.Phrases;
                journeyData   = new HashSet <T>(journeyPhrases.Cast <T>());
                currentPSData = new HashSet <T>(currentPlaySessionPhrases.Cast <T>());
            }

            // Get unfiltered data based on the builder's logic
            var dataList      = builderSelectionFunction();
            int nAfterBuilder = dataList.Count;

            debugString += ("Builder: " + dataList.Count);

            // Filtering based on journey
            if (selectionParams.useJourney && !ConfigAI.forceJourneyIgnore)
            {
                dataList = dataList.FindAll(x => journeyData.Contains(x));
            }
            if (selectionParams.severity == SelectionSeverity.AllRequired)
            {
                if (!CheckRequiredNumberReached(dataList, selectionParams, nAfterBuilder))
                {
                    UnityEngine.Debug.Log(debugString);
                    throw new System.Exception("The teacher could not find " + selectionParams.nRequired + " data instances after applying the journey logic.");
                }
            }
            debugString += (" \tJourney: " + dataList.Count);

            // Filtering based on pack-list history
            PackListHistory sev = selectionParams.packListHistory;

            switch (sev)
            {
            case PackListHistory.NoFilter:
                // we do not care which are picked, in this case
                break;

            case PackListHistory.ForceAllDifferent:
                // filter only by those that have not been found already in this pack, if possible
                dataList = dataList.FindAll(x => !selectionParams.filteringIds.Contains(x.GetId()));
                if (!CheckRequiredNumberReached(dataList, selectionParams, nAfterBuilder))
                {
                    UnityEngine.Debug.Log(debugString);
                    throw new System.Exception("The teacher could not find " + selectionParams.nRequired + " data instances after applying the pack-history logic.");
                }
                break;

            case PackListHistory.RepeatWhenFull:
                // reset the previous pack list if needed
                var tmpDataList = dataList.FindAll(x => !selectionParams.filteringIds.Contains(x.GetId()));
                if (tmpDataList.Count < selectionParams.nRequired)
                {
                    // reset and re-pick
                    selectionParams.filteringIds.Clear();
                    dataList = dataList.FindAll(x => !selectionParams.filteringIds.Contains(x.GetId()));
                }
                else
                {
                    dataList = tmpDataList;
                }
                break;
            }
            debugString += (" \tHistory: " + dataList.Count);

            // Weighted selection on the remaining number
            List <T> selectedList = null;

            if (selectionParams.getMaxData)
            {
                selectedList = dataList;
            }
            else
            {
                selectedList = WeightedDataSelect(dataList, currentPSData, selectionParams.nRequired, table, selectionParams.severity);
            }
            debugString += (" \tSelection: " + selectedList.Count);

            if (ConfigAI.verboseDataSelection)
            {
                UnityEngine.Debug.Log(debugString);
            }

            if (selectedList.Count == 0)
            {
                throw new System.Exception("The teacher could not find any data with the current filters. The game does not seem to be playable at the selected play session.");
            }

            // Update the filtering ids
            if (selectionParams.packListHistory != PackListHistory.NoFilter)
            {
                selectionParams.filteringIds.AddRange(selectedList.ConvertAll <string>(x => x.GetId()).ToArray());
            }

            return(selectedList);
        }