/// <summary>
        /// Method updating the competence state due to a game situation success/failure.
        /// </summary>
        ///
        /// <param name="success"> If this value is set to true the player has successfully completed the game situation, otherwise not. </param>
        public void setGameSituationUpdate(Boolean success)
        {
            loggingPRA("Gamesituation completed - sending evidence to update competences.");
            GameSituation gs = getCurrentGameSituation();

            getCAA().updateCompetenceStateAccordingToGamesituation(gs.Id, success);
        }
        /// <summary>
        /// c-tor creating the object out of a given domain model.
        /// </summary>
        /// <param name="dm"></param>
        public GameSituationStructure(DomainModel dm)
        {
            //adding gs to the structure
            foreach (Situation si in dm.elements.situations.situationList)
            {
                gameSituations.Add(new GameSituation(si.id));
            }
            //adding competences to the gs in the structure
            foreach (SituationRelation sir in dm.relations.situations.situations)
            {
                foreach (CompetenceSituation cs in sir.competences)
                {
                    getGameSituationById(sir.id).Competences.Add(cs.id);
                }
            }
            //adding successors of the gs - at the moment all gs are successors of all gs
            foreach (GameSituation gs1 in gameSituations)
            {
                foreach (GameSituation gs2 in gameSituations)
                {
                    gs1.Successors.Add(gs2);
                }
            }

            //set initial gs
            initialGameSituation = gameSituations[0];
        }
        /// <summary>
        /// Method returning the id of the current game situation player by the player.
        /// </summary>
        ///
        /// <returns> String containing the game situation identification. </returns>
        public String getCurrentGameSituationId()
        {
            GameSituation gs = getCurrentGameSituation();

            if (gs == null)
            {
                return(null);
            }
            return(gs.Id);
        }
        /// <summary>
        /// Method for performing all neccessary operations to run update methods.
        /// </summary>
        ///
        /// <param name="dm"> Specifies the domain model used for the following registration. </param>
        public void registerNewPlayer(DomainModel dm)
        {
            gameSituationStructure = null;
            currentGameSituation   = null;
            gameSituationHistory   = new Dictionary <string, int>();

            GameSituationStructure gss = new GameSituationStructure(dm);

            setGameSituationStructure(gss);
            setCurrentGameSituation(gss.InitialGameSituation);
        }
        /// <summary>
        /// Returns the Id of the next game situation.
        /// </summary>
        ///
        ///
        /// <returns> Identification of the next game situation proposed for the player. </returns>
        public String getNextGameSituationId( )
        {
            if (gameSituationStructure == null)
            {
                loggingPRA("The game situation structure for the player does not exist.");
                return(null);
            }
            GameSituationStructure gss    = gameSituationStructure;
            GameSituation          nextGS = gss.determineNextGameSituation();

            if (nextGS != null)
            {
                updateGameSituationHistory(nextGS);
                return(nextGS.Id);
            }
            return(null);
        }
 /// <summary>
 /// Method for resetting the Asset - if for example the settigns are changed
 /// </summary>
 public void resetAsset()
 {
     this.currentGameSituation = null;
 }
        //TODO: change tmp line
        /// <summary>
        /// Returns the next game situation for a player.
        /// </summary>
        ///
        ///
        /// <returns> The next game situation for the specified player. </returns>
        internal GameSituation determineNextGameSituation( )
        {
            CompetenceBasedAdaptionAsset.Handler.loggingPRA("determining next game situation for player ");
            GameSituation currentGS = CompetenceBasedAdaptionAsset.Handler.getCurrentGameSituation();
            ///tmp line
            //OLD:
            //CompetenceState cs = CompetenceAssessmentHandler.Instance.getCompetenceState(playerId);
            //List<String> mastered = cs.getMasteredCompetencesString();
            //NEW:
            Dictionary <String, double> cs = CompetenceBasedAdaptionAsset.Handler.getCAA().getCompetenceState();
            List <String> mastered         = new List <string>();

            foreach (KeyValuePair <String, double> pair in cs)
            {
                double transitionProbability = ((CompetenceAssessmentAssetSettings)CompetenceBasedAdaptionAsset.Handler.getCAA().Settings).TransitionProbability;
                if (pair.Value >= transitionProbability)
                {
                    mastered.Add(pair.Key);
                }
            }


            //each GS gets evaluated: int describes the number of competences not mastered and in the new game situation
            Dictionary <GameSituation, int> gameSituationEvaluation0 = new Dictionary <GameSituation, int>();

            int minDistanceCompetences = -1;
            int currentDistanceCompetences;

            foreach (GameSituation gs in currentGS.Successors)
            {
                currentDistanceCompetences   = gs.getNrNotMasteredCompetences(mastered);
                gameSituationEvaluation0[gs] = currentDistanceCompetences;
                if (currentDistanceCompetences != 0 && (minDistanceCompetences == -1 || minDistanceCompetences > currentDistanceCompetences))
                {
                    minDistanceCompetences = currentDistanceCompetences;
                }
            }

            //Remove GS with not mastered competences, for which not all prerequisites are mastered!
            CompetenceStructure             compStruct = new CompetenceStructure(CompetenceBasedAdaptionAsset.Handler.getDMA().getDomainModel());
            Dictionary <GameSituation, int> gameSituationEvaluation = new Dictionary <GameSituation, int>();
            Boolean allPrerequisitesMet = true;

            foreach (GameSituation gs in gameSituationEvaluation0.Keys)
            {
                allPrerequisitesMet = true;
                foreach (string com in gs.Competences)
                {
                    if (!mastered.Contains(com))
                    {
                        if (!compStruct.getCompetenceById(com).allPrerequisitesMet(CompetenceBasedAdaptionAsset.Handler.getCAA().getCompetenceState()))
                        {
                            allPrerequisitesMet = false;
                        }
                    }
                }
                if (allPrerequisitesMet)
                {
                    gameSituationEvaluation[gs] = gameSituationEvaluation0[gs];
                }
            }

            if (gameSituationEvaluation.Count == 0)
            {
                CompetenceBasedAdaptionAsset.Handler.loggingPRA("No suitable GS found (minimal number of new competences, all of which have their prerequisites met)");
                //throw new Exception("No suitable GS found (minimal number of new competences, all of which have their prerequisites met)");
                return(null);
            }

            //Determining the GS with the smallest distance which was played least often
            Dictionary <string, int> gameSituationHistory = CompetenceBasedAdaptionAsset.Handler.getGameSituationHistory();
            List <GameSituation>     minDistanceGS        = new List <GameSituation>();
            GameSituation            minPlayedGS          = null;

            foreach (KeyValuePair <GameSituation, int> entry in gameSituationEvaluation)
            {
                if (entry.Value == minDistanceCompetences)
                {
                    minDistanceGS.Add(entry.Key);
                    if (minPlayedGS == null || gameSituationHistory[minPlayedGS.Id] > gameSituationHistory[entry.Key.Id])
                    {
                        minPlayedGS = entry.Key;
                    }
                }
            }

            CompetenceBasedAdaptionAsset.Handler.setCurrentGameSituation(minPlayedGS);

            return(minPlayedGS);
        }
 /// <summary>
 /// Increments the integer counting the number of times a player has player a game situation.
 /// </summary>
 ///
 /// <param name="gs"> Game situation played. </param>
 internal void updateGameSituationHistory(GameSituation gs)
 {
     gameSituationHistory[gs.Id]++;
 }
 /// <summary>
 /// Stores a game situation to a given player id as current game situation.
 /// </summary>
 ///
 /// <param name="gs"> Game situation which is set to be the current GS for the specified player. </param>
 internal void setCurrentGameSituation(GameSituation gs)
 {
     currentGameSituation = gs;
 }