// Note: Assumes that server communication object was previously polled by the activity script to check when it has RoutineStatus.READY.
    //       the script has confirmed that the generator can go ahead.
    public SHLevelConfigGeneratorServer(ActivityServerCommunication para_serverCommunication)
    {
        List<PackagedNextWord> list = null;
        LevelParameters level = new LevelParameters("");

        if(para_serverCommunication!=null){
            list = para_serverCommunication.loadSentences();
        //			list = para_serverCommunication.loadWords();
            level = new LevelParameters(para_serverCommunication.getLevel());

            instruction = LocalisationMang.instructions(para_serverCommunication.getDifficulty()[0],para_serverCommunication.getLevel(),ApplicationID.SERENADE_HERO);

            /*TextAsset ta = (TextAsset) Resources.Load("Localisation_Files/"+para_serverCommunication.language.ToString()+"/Instructions_"+para_serverCommunication.language.ToString(),typeof(TextAsset));
            if(ta != null){

            string text = ta.text;

            foreach(string line in text.Split('\n')){

                string[] values = line.Split(',');

                if(System.Convert.ToInt32(values[0])==(int)ApplicationID.SERENADE_HERO){

                    if(System.Convert.ToInt32(values[1])==level.mode){
                        Debug.Log(line);

                        if((TtsType)System.Enum.Parse(typeof(TtsType), values[2])==level.ttsType){

                            instruction = values[3];
                        }
                    }
                }
            }
            }
            if (instruction==""){
                instruction = "Instructions not available";
            }*/
        }

        int speed = level.speed;

        if (list==null){
            WorldViewServerCommunication.setError("Did not find words");
            return;
        }else if(list.Count==0){
            WorldViewServerCommunication.setError("List of words is empty");
            return;
        }

        if (error){
            list = WordDBCreator.createListPackagedNextWords("SERENADE_HERO");
            level = new LevelParameters(WordDBCreator.getLevel("SERENADE_HERO"));
        }

        lvlArr = new SHeroLevelConfig[list.Count];

        try{

        for(int i=0; i<list.Count; i++)
        {

            AnnotatedSentence sentence = list[i].getAnnotatedSentence();

            bool isWord = false;
            string[] text;
            List<int> indexes = new List<int>();

            isWord = true;
            text = sentence.theSentence.Split(new char[] { '{', '}' }, System.StringSplitOptions.RemoveEmptyEntries);

            List<int> positions = new List<int>();
            int j = -1;

                Debug.Log(sentence.theSentence);
            while ((j = sentence.theSentence.IndexOf('{', j+1)) != -1)
                {
                    positions.Add(j);
                    //Debug.Log(j);
                }

            int total_length = 0;

            for( j = 0;j<text.Length;j++){
                    if (positions.Contains(total_length)){
                        indexes.Add(j);
                        total_length +=2; //Opening and closing brakets
                    }

                    total_length += text[j].Length;
            }

                Debug.Log(sentence.theSentence+" "+indexes.Count+" "+sentence.fillerWords.Count);
                for(int jj =0;jj<sentence.fillerWords.Count;jj++){

                    Debug.Log(sentence.fillerWords[jj]);

                }

                if(sentence.fillerWords.Count>4){
                    List<string> needHaveFillers = new List<string>();//The last fillers are the correct syllables

                    for(int jj=0;jj<indexes.Count;jj++){
                        needHaveFillers.Add(sentence.fillerWords[sentence.fillerWords.Count-1]);
                        sentence.fillerWords.Remove(needHaveFillers[jj]);
                    }

                    while((sentence.fillerWords.Count+indexes.Count)>4){
                        sentence.fillerWords.RemoveAt(Random.Range(0,sentence.fillerWords.Count));
                        Debug.Log("Remove! "+sentence.fillerWords.Count);
                    }

                    foreach(string needFiller in needHaveFillers)
                        sentence.fillerWords.Add(needFiller);

                }

            for(int jj =0;jj<sentence.fillerWords.Count;jj++){

                int k = Random.Range(0,sentence.fillerWords.Count);
                sentence.fillerWords.Add(sentence.fillerWords[k]);
                sentence.fillerWords.Remove(sentence.fillerWords[k]);

            }

            Debug.Log(text+" "+list[i].getAnnotatedSentence().languageArea+" "+list[i].getAnnotatedSentence().difficulty);

            lvlArr[i] = new SHeroLevelConfig(text,indexes.ToArray(),sentence.fillerWords.ToArray(),isWord,speed, list[i].getAnnotatedSentence().languageArea,list[i].getAnnotatedSentence().difficulty  );
        }

        for(int j=1;j<lvlArr.Length;j++){
            int r_j = Random.Range(1,lvlArr.Length);
            SHeroLevelConfig aux = lvlArr[r_j];
            lvlArr[r_j] = lvlArr[j];
            lvlArr[j] = aux;
        }
        }catch(System.Exception e){

        WorldViewServerCommunication.setError(e.Message);
        return;
        }
    }
    public WAMLevelConfigGeneratorServer(ActivityServerCommunication para_serverCommunication)
    {
        //Debug.LogWarning( "More than one pattern per game?" );

        List<PackagedNextWord> list = null;
        LevelParameters level = new LevelParameters("");

        if(para_serverCommunication!=null){
            list = para_serverCommunication.loadWords();
            level = new LevelParameters(para_serverCommunication.getLevel());
            instruction = LocalisationMang.instructions(para_serverCommunication.getDifficulty()[0],para_serverCommunication.getLevel(),ApplicationID.WHAK_A_MOLE);
        }

        if (list==null){
            WorldViewServerCommunication.setError("Did not find words");
            return;
        }else if(list.Count==0){
            WorldViewServerCommunication.setError("List of words is empty");
            return;
        }else{

            foreach(PackagedNextWord w in list){
                if (w.getAnnotatedWord().getWordProblems().Count==0){
                    WorldViewServerCommunication.setError("Word '"+w.getAnnotatedWord().getWord()+"' do not have problems");
                    return;
                }else if(w.getAnnotatedWord().getWordProblems()[0].matched.Length==0){
                    WorldViewServerCommunication.setError("Word '"+w.getAnnotatedWord().getWord()+"' do not have problems");
                    return;
                }
            }
        }

        //List<WAMLevelConfig> list_levels = new List<WAMLevelConfig>();

        try{

            bool patternSound = (level.ttsType==TtsType.SPOKEN2WRITTEN);

            if(WorldViewServerCommunication.tts==null){
                patternSound = false;
            }

            List<PackagedNextWord> words = new List<PackagedNextWord>();
            List<PackagedNextWord> fillers = new List<PackagedNextWord>();

            foreach( PackagedNextWord nw in list){

                if(nw.getFiller()){ fillers.Add(nw);
                }else{ words.Add(nw); }
            }

            string[] deckA = new string[words.Count];
            string[] deckB = new string[fillers.Count];

            string pattern = "";
            if(words.Count==0){
                WorldViewServerCommunication.setError("Correct words not available for difficulty ("+para_serverCommunication.getDifficulty()[0]+","+para_serverCommunication.getDifficulty()[1]);
                return;
            }

            int languageArea = words[0].getAnnotatedWord().getWordProblems()[0].category;
            int difficulty = words[0].getAnnotatedWord().getWordProblems()[0].index;
            string description = WorldViewServerCommunication.userProfile.userProblems.getDifficultiesDescription().getDifficulties()[languageArea][difficulty].getDescriptionsToString();

            if(level.mode==0){//DEPRECATED

                string phoneme = "";

                foreach(string desc in description.Split (',')){
                    if (desc.Contains("-")){
                        if (phoneme=="")
                            phoneme += desc.Split('-')[1];
                        else
                            phoneme += " / "+desc.Split('-')[1];
                    }
                }

                if(phoneme==""){
                    patternSound = false;
                    pattern = description;
                }else
                    pattern = "/"+phoneme+"/";

                for (int i=0;i<deckA.Length;i++){

                    deckA[i] = WorldViewServerCommunication.userProfile.userProblems.getDifficultiesDescription().getDifficulties()[languageArea][difficulty].descriptions[0].Split('-')[0];
                }

                for (int i=0;i<deckB.Length;i++){

                    int fillerLanguageArea = fillers[i].getAnnotatedWord().getWordProblems()[0].category;
                    int fillerDifficulty = fillers[i].getAnnotatedWord().getWordProblems()[0].index;

                    deckB[i] = WorldViewServerCommunication.userProfile.userProblems.getDifficultiesDescription().getDifficulties()[fillerLanguageArea][fillerDifficulty].descriptions[0].Split('-')[0];

                }

            }else if (level.mode==1){//EN, vowels & consonants, monkeys with words, phoneme on the pattern

                string phoneme = "";

                foreach(string desc in description.Split (',')){
                    if (desc.Contains("-")){
                        if (phoneme=="")
                            phoneme += desc.Split('-')[1];
                        else
                            phoneme += " / "+desc.Split('-')[1];
                    }
                }

                if(!patternSound){
                    GhostbookManagerLight gbMang = GhostbookManagerLight.getInstance();
                    pattern = gbMang.createExplanation(languageArea,difficulty);//Human readable description
                }else{
                    if(phoneme==""){
                        patternSound = false;
                        GhostbookManagerLight gbMang = GhostbookManagerLight.getInstance();
                        pattern = gbMang.createExplanation(languageArea,difficulty);//Human readable description
                    }else{
                        pattern = "/"+phoneme+"/";
                        if(!WorldViewServerCommunication.tts.test(pattern)){//Phonemes are prerecorded
                            patternSound = false;
                            GhostbookManagerLight gbMang = GhostbookManagerLight.getInstance();
                            pattern = gbMang.createExplanation(languageArea,difficulty);//Human readable description
                        }
                    }
                }
                for (int i=0;i<deckA.Length;i++){
                    deckA[i] = words[i].getAnnotatedWord().getWord();
                }

                for (int i=0;i<deckB.Length;i++){
                    deckB[i] = fillers[i].getAnnotatedWord().getWord();
                }

            }else if(level.mode==2){//Suffix, EN, pattern is the suffix

                //pattern = "-"+WorldViewServerCommunication.userProfile.userProblems.getDifficultiesDescription().getDifficulties()[languageArea][difficulty].descriptions[0].Split('-')[0];

                for (int i=0;i<deckA.Length;i++){
                    deckA[i] = words[i].getAnnotatedWord().getWord();
                }

                for (int i=0;i<deckB.Length;i++){
                    deckB[i] = fillers[i].getAnnotatedWord().getWord();
                }

                MatchedData problem = words[0].getAnnotatedWord().getWordProblems()[0].matched[0];
                pattern = "-"+words[0].getAnnotatedWord().getWord().Substring(problem.start,problem.end-problem.start);

            }else if(level.mode==3){//Prefix, EN, use

                //pattern = WorldViewServerCommunication.userProfile.userProblems.getDifficultiesDescription().getDifficulties()[languageArea][difficulty].descriptions[0].Split('-')[0]+"-";

                for (int i=0;i<deckA.Length;i++){
                    deckA[i] = words[i].getAnnotatedWord().getWord();
                }

                for (int i=0;i<deckB.Length;i++){
                    deckB[i] = fillers[i].getAnnotatedWord().getWord();
                }

                MatchedData problem = words[0].getAnnotatedWord().getWordProblems()[0].matched[0];
                pattern = words[0].getAnnotatedWord().getWord().Substring(problem.start,problem.end-problem.start)+"-";

            }else if (level.mode==4){//COnfusing letters (EN) and letter similarity (GR); letter to letter

                int size =level.batchSize/2;

                deckA = new string[size];

                if(para_serverCommunication.language==LanguageCode.EN){//get the pair of confusing letters from the difficulty description, e.g. b/d
                    deckB = new string[1];

                    deckA[0] = WorldViewServerCommunication.userProfile.userProblems.getDifficultiesDescription().getDifficulties()[languageArea][difficulty].descriptions[0].Split('/')[0];
                    deckB[0] = WorldViewServerCommunication.userProfile.userProblems.getDifficultiesDescription().getDifficulties()[languageArea][difficulty].descriptions[0].Split('/')[1];

                    for(int k=1;k<deckA.Length;k++){

                        deckA[k] = deckA[0];
                    }
                }else{

                    int letter = Random.Range(0,description.Split(',').Length);//The description are the letters separated by commas a,A,e

                    deckB = new string[description.Split(',').Length-1];

                    int i = 0;
                    for(int ii = 0;ii<description.Split(',').Length;ii++){
                        if (ii == letter){
                            deckA[0] = description.Split(',')[letter];
                        }else{
                            deckB[i++] = description.Split(',')[ii];
                        }
                    }
                }

                pattern = deckA[0];

            }else if (level.mode==5){//GR, prefixes and derivational; pattern is a word

                pattern = words[0].getAnnotatedWord().getWord();

                deckA = new string[deckA.Length-1];
                for (int i=0;i<deckA.Length;i++){
                    deckA[i] = words[i+1].getAnnotatedWord().getWord();
                }

                for (int i=0;i<deckB.Length;i++){
                    deckB[i] = fillers[i].getAnnotatedWord().getWord();
                }

            }else if (level.mode==6){//GR, letter similarity; pattern is a the first letter of correct words

                for (int i=0;i<deckA.Length;i++){
                    deckA[i] = words[i].getAnnotatedWord().getWord();
                }

                for (int i=0;i<deckB.Length;i++){
                    deckB[i] = fillers[i].getAnnotatedWord().getWord();
                }

                if(patternSound){
                    //TODO: record Greek phonemes
                    pattern = words[0].getAnnotatedWord().getWord().Substring(0,1);
                    //pattern ="/"+ words[0].getAnnotatedWord().getGraphemesPhonemes()[0].phoneme+"/";
                    if(! WorldViewServerCommunication.tts.test(pattern)){
                        patternSound = false;
                        pattern = words[0].getAnnotatedWord().getWord().Substring(0,1);//first letter
                    }
                }else{
                    pattern = words[0].getAnnotatedWord().getWord().Substring(0,1);//first letter
                }

            }else if(level.mode==7){//EN with confusing and GR with GP correspondence, pattern is the grapheme/phoneme of the correct words

                MatchedData problem = words[0].getAnnotatedWord().getWordProblems()[0].matched[0];
                pattern = words[0].getAnnotatedWord().getWord().Substring(problem.start,problem.end-problem.start);//grapheme

                for (int i=0;i<deckA.Length;i++){
                    deckA[i] = words[i].getAnnotatedWord().getWord();
                }

                for (int i=0;i<deckB.Length;i++){
                    deckB[i] = fillers[i].getAnnotatedWord().getWord();
                }
            }

            if(patternSound){//This should be handled above, additional precaution
                if(WorldViewServerCommunication.tts!=null){
                    if(!WorldViewServerCommunication.tts.test(pattern))
                        patternSound = false;
                }
            }

            lvlArr = new WAMLevelConfig[1]{ new WAMLevelConfig(pattern ,deckA,deckB ,patternSound,level.speed,languageArea,difficulty)};

        }catch(System.Exception e){

            WorldViewServerCommunication.setError(e.Message);
            return;
        }

        counter = 0;
    }
 void Awake()
 {
     GameObject servComObj = getServerObject();
     serverCommunication = servComObj.GetComponent<ActivityServerCommunication>();
 }
    public PDLevelConfigGeneratorServer(ActivityServerCommunication para_serverCommunication)
    {
        List<PackagedNextWord> list = null;
        LevelParameters level = new LevelParameters("");

        if(para_serverCommunication!=null){
            list = para_serverCommunication.loadWords();
            level = new LevelParameters(para_serverCommunication.getLevel());
            instruction = LocalisationMang.instructions(para_serverCommunication.getDifficulty()[0],para_serverCommunication.getLevel(),ApplicationID.ENDLESS_RUNNER);

            /*TextAsset ta = (TextAsset) Resources.Load("Localisation_Files/"+para_serverCommunication.language.ToString()+"/Instructions_"+para_serverCommunication.language.ToString(),typeof(TextAsset));
            if(ta != null){

            string text = ta.text;

            foreach(string line in text.Split('\n')){

                string[] values = line.Split(',');

                if(System.Convert.ToInt32(values[0])==(int)ApplicationID.ENDLESS_RUNNER){

                    if(System.Convert.ToInt32(values[1])==level.mode){
                        Debug.Log(line);

                        if((TtsType)System.Enum.Parse(typeof(TtsType), values[2])==level.ttsType){

                            instruction = values[3];
                        }
                    }
                }
            }
            }
            if (instruction==""){
                instruction = "";
            }*/
        }

        if (list==null){
            WorldViewServerCommunication.setError("Did not find words");
            return;
        }else if(list.Count==0){
            WorldViewServerCommunication.setError("List of words is empty");
            return;
        }

        //if (error){
        //	list = WordDBCreator.createListPackagedNextWords("ENDLESS_RUNNER");
        //	level = new LevelParameters(WordDBCreator.getLevel("ENDLESS_RUNNER"));
        //}

        List<PDLevelConfig> hardCodedList = new List<PDLevelConfig>();

        try{

            for (int i=0;i<list.Count;i+=level.accuracy){

                List<string> words = new List<string>();
                List<int> knocks = new List<int>();
                List<int> langArea = new List<int>();
                List<int> diff = new List<int>();

                for(int j=i;j<list.Count;j++){

                    words.Add(list[j].annotatedWord.getWord());
                    langArea.Add(list[j].annotatedWord.getWordProblems()[0].category);
                    diff.Add(list[j].annotatedWord.getWordProblems()[0].index);

                    if(level.mode==0){
                        knocks.Add(list[j].annotatedWord.getSyllables().Length);
                    }else{
                        knocks.Add(list[j].annotatedWord.getGraphemesPhonemes().Count);
                    }

                    if (words.Count==level.accuracy)
                        break;
                }

                hardCodedList.Add( new PDLevelConfig(words.ToArray(),knocks.ToArray(),langArea.ToArray(),diff.ToArray(),words.Count*(4-level.speed)));

            }

            hardCodedArr = hardCodedList.ToArray();
        for(int j=1;j<hardCodedArr.Length;j++){
            int r_j = Random.Range(1,hardCodedArr.Length);
            PDLevelConfig aux = hardCodedArr[r_j];
            hardCodedArr[r_j] = hardCodedArr[j];
            hardCodedArr[j] = aux;
        }

        }catch(System.Exception e){

        WorldViewServerCommunication.setError(e.Message);
        return;
        }

        counter = 0;
    }
    // Note: Assumes that server communication object was previously polled by the activity script to check when it has RoutineStatus.READY.
    //       the script has confirmed that the generator can go ahead.
    public BBLevelConfigGeneratorServer(ActivityServerCommunication para_serverCommunication)
    {
        List<PackagedNextWord> list = null;
        LevelParameters level = new LevelParameters("");

        if(para_serverCommunication!=null){
            list = para_serverCommunication.loadWords();
            level = new LevelParameters(para_serverCommunication.getLevel());

            instruction = LocalisationMang.instructions(para_serverCommunication.getDifficulty()[0],para_serverCommunication.getLevel(),ApplicationID.EYE_EXAM);

        }

        if (list==null){
            WorldViewServerCommunication.setError("Did not find words");
            return;
        }else if(list.Count==0){
            WorldViewServerCommunication.setError("List of words is empty");
            return;
        }else{
            if ((level.mode!=0))//Words must have a difficulty unless we are only using syllables

            foreach(PackagedNextWord w in list){
                if (w.getAnnotatedWord().getWordProblems().Count==0){
                    WorldViewServerCommunication.setError("Word '"+w.getAnnotatedWord().getWord()+"' do not have problems");
                    return;
                }else if(w.getAnnotatedWord().getWordProblems()[0].matched.Length==0){
                    WorldViewServerCommunication.setError("Word '"+w.getAnnotatedWord().getWord()+"' do not have problems");
                    return;
                }
            }
        }

        List<BBLevelConfig> reqList = new List<BBLevelConfig>();

        try{

        for(int i=0; i<list.Count; i++)
        {
            AnnotatedWord tmpAWord = list[i].annotatedWord;
            string bridgeWord = tmpAWord.getWord();

            if(level.mode==0){//(deprecated for EN) GR syllable division

                List<int> wordSylls = tmpAWord.getSyllSplitPositions();

                int syllableIndex = UnityEngine.Random.Range(0,wordSylls.Count);

                if(syllableIndex==0){

                    HighlightDesc hd= new HighlightDesc(0,wordSylls[0]);

                    if(WorldViewServerCommunication.userProfile.language=="EN")
                            reqList.Add(new BBLevelConfig(bridgeWord,new List<HighlightDesc>() {hd},"First syllable",TtsType.WRITTEN2WRITTEN, tmpAWord.getWordProblems()[0].category,tmpAWord.getWordProblems()[0].index));
                    else
                            reqList.Add(new BBLevelConfig(bridgeWord,new List<HighlightDesc>() {hd},"πρώτη συλλαβή",TtsType.WRITTEN2WRITTEN, tmpAWord.getWordProblems()[0].category,tmpAWord.getWordProblems()[0].index));

                }else if(syllableIndex==wordSylls.Count-1){

                    HighlightDesc hd= new HighlightDesc(wordSylls[wordSylls.Count-1]+1,bridgeWord.Length-1);
                    if(WorldViewServerCommunication.userProfile.language=="EN")

                            reqList.Add(new BBLevelConfig(bridgeWord,new List<HighlightDesc>() {hd},"Last syllable",TtsType.WRITTEN2WRITTEN, tmpAWord.getWordProblems()[0].category,tmpAWord.getWordProblems()[0].index));

                    else
                            reqList.Add(new BBLevelConfig(bridgeWord,new List<HighlightDesc>() {hd},"Τελευταία συλλαβή",TtsType.WRITTEN2WRITTEN, tmpAWord.getWordProblems()[0].category,tmpAWord.getWordProblems()[0].index));

                }else{

                    HighlightDesc hd= new HighlightDesc(wordSylls[syllableIndex-1]+1,wordSylls[syllableIndex]-1);
                    string position = "";

                    if(WorldViewServerCommunication.userProfile.language=="EN"){

                        switch(syllableIndex){

                        case 1: position = "Second";break;
                        case 2: position = "Third";break;
                        case 3: position = "Fourth";break;
                        case 4: position = "Fifth";break;
                        case 5: position = "Sixth";break;
                        }
                            reqList.Add(new BBLevelConfig(bridgeWord,new List<HighlightDesc>() {hd},position+" syllable",TtsType.WRITTEN2WRITTEN, tmpAWord.getWordProblems()[0].category,tmpAWord.getWordProblems()[0].index));
                    }else{

                        switch(syllableIndex){
                        case 1: position = "δεύτερη";break;
                        case 2: position = "τρίτη";break;
                        case 3: position = "τέταρτη";break;

                        }
                            reqList.Add(new BBLevelConfig(bridgeWord,new List<HighlightDesc>() {hd},position+" συλλαβή",TtsType.WRITTEN2WRITTEN, tmpAWord.getWordProblems()[0].category,tmpAWord.getWordProblems()[0].index));

                    }
                }

            }else if(level.mode==6){//GR inflexional and prefixes and letter similarity

                MatchedData[] matches = tmpAWord.getWordProblems()[0].matched;

                List<HighlightDesc> listMatches = new List<HighlightDesc>();
                string pattern = tmpAWord.getWord().Substring(matches[0].start,matches[0].end-matches[0].start);
                foreach (MatchedData match in matches)
                    if(tmpAWord.getWord().Substring(match.start,match.end-match.start)==pattern)
                        listMatches.Add( new HighlightDesc(match.start,match.end-1) );

                reqList.Add(new BBLevelConfig(bridgeWord,listMatches,pattern,level.ttsType, tmpAWord.getWordProblems()[0].category,tmpAWord.getWordProblems()[0].index));

            }else{//EN

                int languageArea = tmpAWord.getWordProblems()[0].category;
                int difficulty = tmpAWord.getWordProblems()[0].index;
                MatchedData[] matches = tmpAWord.getWordProblems()[0].matched;

                string description = WorldViewServerCommunication.userProfile.userProblems.getDifficultiesDescription().getDifficulties()[languageArea][difficulty].getDescriptionsToString();

                if(level.mode==4){//vowel or consonants, TTS

                    string phoneme = "";

                    foreach(string pattern in description.Split (',')){
                        if (pattern.Contains("-")){
                            if (phoneme=="")
                                phoneme += pattern.Split('-')[1];
                            else
                                phoneme += " / "+pattern.Split('-')[1];
                        }
                    }

                    List<HighlightDesc> highlights = new List<HighlightDesc>();

                    foreach(MatchedData match in matches){
                        highlights.Add(new HighlightDesc(match.start,match.end-1));
                    }

                    string pattern2 = "";
                    if(level.ttsType==TtsType.WRITTEN2WRITTEN){
                            GhostbookManagerLight gbMang = GhostbookManagerLight.getInstance();
                            pattern2 = gbMang.createExplanation(languageArea,difficulty);//Human readable description
                    }else{
                        if(phoneme==""){
                                level.ttsType=TtsType.WRITTEN2WRITTEN;
                                GhostbookManagerLight gbMang = GhostbookManagerLight.getInstance();
                                pattern2 = gbMang.createExplanation(languageArea,difficulty);//Human readable description
                        }else{
                                pattern2 = "/"+phoneme+"/";
                                if(!WorldViewServerCommunication.tts.test(pattern2)){//Phonemes are prerecorded
                                    level.ttsType=TtsType.WRITTEN2WRITTEN;
                                    GhostbookManagerLight gbMang = GhostbookManagerLight.getInstance();
                                    pattern2 = gbMang.createExplanation(languageArea,difficulty);//Human readable description
                                }
                        }
                    }

                    reqList.Add(new BBLevelConfig(bridgeWord,highlights ,pattern2,level.ttsType, tmpAWord.getWordProblems()[0].category,tmpAWord.getWordProblems()[0].index));

                }else if(level.mode==1){//EN suffix

                    List<HighlightDesc> listMatches = new List<HighlightDesc>();

                    foreach (MatchedData match in matches)
                        listMatches.Add( new HighlightDesc(match.start,match.end-1) );

                        reqList.Add(new BBLevelConfig(bridgeWord,listMatches,"-"+description,level.ttsType, tmpAWord.getWordProblems()[0].category,tmpAWord.getWordProblems()[0].index));

                }else if(level.mode==2){//EN prefix

                    List<HighlightDesc> listMatches = new List<HighlightDesc>();

                    foreach (MatchedData match in matches)
                        listMatches.Add( new HighlightDesc(match.start,match.end-1) );

                    reqList.Add(new BBLevelConfig(bridgeWord,listMatches,description+"-",level.ttsType, tmpAWord.getWordProblems()[0].category,tmpAWord.getWordProblems()[0].index));

                }else{//5, EN confusing letters

                    List<HighlightDesc> listMatches = new List<HighlightDesc>();

                    description = bridgeWord.Substring(matches[0].start,matches[0].end-matches[0].start);

                    foreach (MatchedData match in matches){
                        if(bridgeWord.Substring(match.start,match.end-match.start).Equals(description))
                               listMatches.Add( new HighlightDesc(match.start,match.end-1) );
                    }
                    reqList.Add(new BBLevelConfig(bridgeWord,listMatches,description,level.ttsType, tmpAWord.getWordProblems()[0].category,tmpAWord.getWordProblems()[0].index));

                }
            }
        }

        hardCodedArr = reqList.ToArray();

        for(int j=1;j<hardCodedArr.Length;j++){
            int r_j = Random.Range(1,hardCodedArr.Length);
            BBLevelConfig aux = hardCodedArr[r_j];
            hardCodedArr[r_j] = hardCodedArr[j];
            hardCodedArr[j] = aux;
        }

        }catch(System.Exception e){

        WorldViewServerCommunication.setError(e.Message);
        return;
        }

        counter = 0;
    }
    // Note: Assumes that server communication object was previously polled by the activity script to check when it has RoutineStatus.READY.
    //       the script has confirmed that the generator can go ahead.
    public TDLevelConfigGeneratorServer(ActivityServerCommunication para_serverCommunication)
    {
        List<PackagedNextWord> list = null;
        LevelParameters level = new LevelParameters("");

        if(para_serverCommunication!=null){
            list = para_serverCommunication.loadWords();
            level = new LevelParameters(para_serverCommunication.getLevel());
            instruction = LocalisationMang.instructions(para_serverCommunication.getDifficulty()[0],para_serverCommunication.getLevel(),ApplicationID.TRAIN_DISPATCHER);

        }

        if (list==null){
            WorldViewServerCommunication.setError("Did not find words");
            return;
        }else if(list.Count==0){
            WorldViewServerCommunication.setError("List of words is empty");
            return;
        }else{

            foreach(PackagedNextWord w in list){
                if (w.getAnnotatedWord().getWordProblems().Count==0){
                    WorldViewServerCommunication.setError("Word '"+w.getAnnotatedWord().getWord()+"' do not have problems");
                    return;
                }else if(w.getAnnotatedWord().getWordProblems()[0].matched.Length==0){
                    WorldViewServerCommunication.setError("Word '"+w.getAnnotatedWord().getWord()+"' do not have problems");
                    return;
                }
            }
        }

        List<TDLevelConfig> reqList = new List<TDLevelConfig>();

        try{

        for(int i=0; i<list.Count; i++)
        {
            AnnotatedWord tmpAWord = list[i].annotatedWord;
            string[] syllables;

            if(level.mode==0){//Syllables

                syllables = tmpAWord.getSyllables();

            }else if(level.mode==1){//Suffix
                syllables = new string[2];

                syllables[0] = tmpAWord.getWord().Substring(0,tmpAWord.getWordProblems()[0].matched[0].start);
                syllables[1] = tmpAWord.getWord().Substring(tmpAWord.getWordProblems()[0].matched[0].start,tmpAWord.getWordProblems()[0].matched[0].end-tmpAWord.getWordProblems()[0].matched[0].start);

            }else if(level.mode==2){//Prefix
                syllables = new string[2];

                syllables[0] = tmpAWord.getWord().Substring(0,tmpAWord.getWordProblems()[0].matched[0].end);
                syllables[1] = tmpAWord.getWord().Substring(tmpAWord.getWordProblems()[0].matched[0].end,tmpAWord.getWord().Length-tmpAWord.getWordProblems()[0].matched[0].end);

            }else{//Graphemes

                syllables = new string[tmpAWord.getGraphemesPhonemes().Count];

                for(int j=0;j<syllables.Length;j++){

                    syllables[j] = tmpAWord.getGraphemesPhonemes()[j].grapheme;

                }

            }

            reqList.Add(new TDLevelConfig(tmpAWord.getWord(),syllables, tmpAWord.getWordProblems()[0].category,tmpAWord.getWordProblems()[0].index ,level.speed));

        }

        hardCodedArr = reqList.ToArray();

        for(int j=1;j<hardCodedArr.Length;j++){
            int r_j = Random.Range(1,hardCodedArr.Length);
            TDLevelConfig aux = hardCodedArr[r_j];
            hardCodedArr[r_j] = hardCodedArr[j];
            hardCodedArr[j] = aux;
        }
        }catch(System.Exception e){

        WorldViewServerCommunication.setError(e.Message);
        return;
        }
        counter = 0;
    }
예제 #7
0
    //int status = 0;
    void Update()
    {
        if (connection!=null){
            //server_script
            if((connection.status()==RoutineStatus.READY ) ){//||(connection.status()==RoutineStatus.IDLE)

                UserLogNoTimestamp log = new UserLogNoTimestamp(userLoginData.username,ApplicationID.LOGGING_SCREEN,Tag.LOGIN);
                log.setValue("Connected");
                server_script.logData(log);//Log successfull log in//also change the status of the connection to IDLE//Maybe too late
                connection = new ConnectionError("Connected",RoutineStatus.IDLE);
                wvServCom =  server.AddComponent<WorldViewServerCommunication>();//This script will launch on Awake a request User Details
                acServCom = server.AddComponent<ActivityServerCommunication>();

            }else if(connection.status()==RoutineStatus.ERROR){

                connectingInProgressFlag = false;

                setConnectButtonVisibility(true);

                GetRoutine  server_response = server_script.errorHandler(connection);

                UserLogNoTimestamp log = new UserLogNoTimestamp(userLoginData.username,ApplicationID.LOGGING_SCREEN,Tag.LOGIN);
                log.setValue(server_response.getError());

                server_script.logData(log);//Log fail log in

                error = server_response.getError();
                connection = null;
                return;
            }else if(connection.status()==RoutineStatus.WAIT){
                //GUI.Label(new Rect(20,220,500,20), "Connecting...");
                return;
            }
        }else
            return;

        downloader(false);

        if(wvServCom.Loading().status()==RoutineStatus.READY){

            message = "Loading saved data";
            SaveFileManager.loadSaveFromPlayerDownload(wvServCom.loadSavefile(),wvServCom.language,WorldViewServerCommunication.userProfile.getLiteracyProfile());//status changes to IDLE

            acServCom.setUserDetails(wvServCom.getUsername(),wvServCom.getUserID(),wvServCom.language);

            BinaryFormatter bf = new BinaryFormatter();
            FileStream file = File.Create (Application.persistentDataPath + "/username.gd");
            userLoginData.language = LocalisationMang.langCode;
            bf.Serialize(file, userLoginData);
            file.Close();

            Debug.LogWarning("Removed the flip between Milton and Monica");

            WorldViewServerCommunication.clearError();

            Application.LoadLevel("PlayerCustomisationScene");

        }else if(wvServCom.Loading().status()==RoutineStatus.WAIT){
            return;
        }else if(wvServCom.Loading().status()==RoutineStatus.ERROR){

            error = wvServCom.Loading().getError();
            connectingInProgressFlag = false;

            //loading = false;
            //askedForSaveFile = false;
            //loadedSaveFlag = false;
            setConnectButtonVisibility(true);
            connection = null;
        }
    }
    public MSLevelConfigGeneratorServer(ActivityServerCommunication para_serverCommunication)
    {
        List<PackagedNextWord> list = null;
        LevelParameters level = new LevelParameters("");

        if(para_serverCommunication!=null){
            list = para_serverCommunication.loadWords();
            level = new LevelParameters(para_serverCommunication.getLevel());
            instruction = LocalisationMang.instructions(para_serverCommunication.getDifficulty()[0],para_serverCommunication.getLevel(),ApplicationID.MAIL_SORTER);

        }

        if (list==null){
            WorldViewServerCommunication.setError("Did not find words");
            return;

        }else if(list.Count==0){

            WorldViewServerCommunication.setError("List of words is empty");
            return;

        }else{

            foreach(PackagedNextWord w in list){
                if (w.getAnnotatedWord().getWordProblems().Count==0){
                    WorldViewServerCommunication.setError("Word '"+w.getAnnotatedWord().getWord()+"' do not have problems");
                    return;
                }else if(w.getAnnotatedWord().getWordProblems()[0].matched.Length==0){
                    WorldViewServerCommunication.setError("Word '"+w.getAnnotatedWord().getWord()+"' do not have problems");
                    return;
                }
            }
        }

        if(WorldViewServerCommunication.tts==null){
            level.ttsType = TtsType.WRITTEN2WRITTEN;

        }

        List<MSLevelConfig> lvlList = new List<MSLevelConfig>();
        int idx = 0;
        try{

            while(idx<list.Count){

            string[] deckA = new string[level.accuracy+1];
            string[] deckB = new string[level.accuracy+1];

            int[] languageAreas = new int[level.accuracy+1];
            int[] difficulties = new int[level.accuracy+1];

            for (int j =0;j<deckA.Length;j++){

                int languageArea = list[idx+j].getAnnotatedWord().getWordProblems()[0].category;
                int  difficulty = list[idx+j].getAnnotatedWord().getWordProblems()[0].index;

                string description = WorldViewServerCommunication.userProfile.userProblems.getDifficultiesDescription().getDifficulties()[languageArea][difficulty].getDescriptionsToString();

                languageAreas[j] = languageArea;
                difficulties[j] = difficulty;

                if(level.mode==0){//EN consonants & vowels
                    deckB[j] = list[idx+j].getAnnotatedWord().getWord();

                    string phoneme = "";

                    foreach(string desc in description.Split (',')){
                        if (desc.Contains("-")){
                            if (phoneme=="")
                                phoneme += desc.Split('-')[1];
                            else
                                phoneme += " / "+desc.Split('-')[1];
                        }
                    }

                        if(level.ttsType==TtsType.WRITTEN2WRITTEN){
                            GhostbookManagerLight gbMang = GhostbookManagerLight.getInstance();
                            deckA[j] = gbMang.createExplanation(languageAreas[j],difficulties[j]);//Human readable description

                        }else{

                    if(phoneme==""){
                            level.ttsType = TtsType.WRITTEN2WRITTEN;

                            GhostbookManagerLight gbMang = GhostbookManagerLight.getInstance();
                            deckA[j] = gbMang.createExplanation(languageAreas[j],difficulties[j]);//Human readable description

                    }else{
                            if(!WorldViewServerCommunication.tts.test("/"+phoneme+"/")){//Phonemes are prerecorded
                                level.ttsType = TtsType.WRITTEN2WRITTEN;
                                GhostbookManagerLight gbMang = GhostbookManagerLight.getInstance();
                                deckA[j] = gbMang.createExplanation(languageAreas[j],difficulties[j]);//Human readable description
                            }else{

                                deckA[j] = "/"+phoneme+"/";
                            }

                    }

                        }

                }else if(level.mode==1){//Suffix
                    deckB[j] = list[idx+j].getAnnotatedWord().getWord();

                    //deckB[j] = "-"+list[idx+j].getAnnotatedWord().getSuffix();//getSyllables()[list[idx+j].getAnnotatedWord().getSyllables().Length-1];
                    if(para_serverCommunication.language==LanguageCode.EN)
                        deckA[j] = "-"+WorldViewServerCommunication.userProfile.userProblems.getDifficultiesDescription().getDifficulties()[languageArea][difficulty].descriptions[0].Split('-')[0];
                    else{

                            int start = list[idx+j].getAnnotatedWord().getWordProblems()[0].matched[0].start;
                            int end = list[idx+j].getAnnotatedWord().getWordProblems()[0].matched[0].end;

                            //Debug.Log(list[idx+j].getAnnotatedWord().getWord());
                            deckA[j] = "-"+list[idx+j].getAnnotatedWord().getWord().Substring(start,end-start);
                    }

                }else if(level.mode==2){//Prefix
                    deckB[j] = list[idx+j].getAnnotatedWord().getWord();
                    deckA[j] = WorldViewServerCommunication.userProfile.userProblems.getDifficultiesDescription().getDifficulties()[languageArea][difficulty].descriptions[0].Split('-')[0]+"-";
                }else if(level.mode==3){//GR GP or EN blends

                    deckB[j] = list[idx+j].getAnnotatedWord().getWord();

                    //Grapheme
                    deckA[j] = list[idx+j].getAnnotatedWord().getWord().Substring(list[idx+j].getAnnotatedWord().getWordProblems()[0].matched[0].start,list[idx+j].getAnnotatedWord().getWordProblems()[0].matched[0].end-list[idx+j].getAnnotatedWord().getWordProblems()[0].matched[0].start);

                    //TODO: blends should use recorded sounds

                    if(level.ttsType==TtsType.WRITTEN2SPOKEN){//GR
                        if(WorldViewServerCommunication.tts!=null){
                                bool correct = true;
                                foreach(string s in deckA){
                                    if(!WorldViewServerCommunication.tts.test(s)){
                                        correct = false;
                                        break;
                                    }
                                }
                                if(!correct){
                                    level.ttsType=TtsType.WRITTEN2WRITTEN;
                                }
                        }else{
                                level.ttsType=TtsType.WRITTEN2WRITTEN;

                        }
                    }
                }
            }

            idx += deckA.Length;

            for(int i =0;i<deckA.Length;i++){
                int j = Random.Range(0,deckA.Length);

                string a = deckA[i];
                deckA[i] =deckA[j];
                deckA[j] = a;

                a = deckB[i];
                deckB[i] =deckB[j];
                deckB[j] = a;

                int la = languageAreas[i];
                languageAreas[i] = languageAreas[j];

                languageAreas[j] = la;

                int d = difficulties[i];
                difficulties[i] = difficulties[j];
                difficulties[j] = d;

            }

            lvlList.Add(new MSLevelConfig(deckB,deckA,level.ttsType,level.speed,languageAreas,difficulties));

        }
        }catch(System.Exception e){

            WorldViewServerCommunication.setError(e.Message);
            return;
        }
        lvlArr = lvlList.ToArray();
        counter = 0;
    }
    public HarvestLevelConfigGeneratorServer(ActivityServerCommunication para_serverCommunication)
    {
        List<PackagedNextWord> list = null;
        LevelParameters level = new LevelParameters("");

        if(para_serverCommunication!=null){
            list = para_serverCommunication.loadWords();
            level = new LevelParameters(para_serverCommunication.getLevel());
            instruction = LocalisationMang.instructions(para_serverCommunication.getDifficulty()[0],para_serverCommunication.getLevel(),ApplicationID.HARVEST);

            /*TextAsset ta = (TextAsset) Resources.Load("Localisation_Files/"+para_serverCommunication.language.ToString()+"/Instructions_"+para_serverCommunication.language.ToString(),typeof(TextAsset));
            if(ta != null){

            string text = ta.text;

            foreach(string line in text.Split('\n')){

                string[] values = line.Split(',');

                if(System.Convert.ToInt32(values[0])==(int)ApplicationID.HARVEST){

                    if(System.Convert.ToInt32(values[1])==level.mode){
                        Debug.Log(line);

                        if((TtsType)System.Enum.Parse(typeof(TtsType), values[2])==level.ttsType){

                            instruction = values[3];
                        }
                    }
                }
            }
            }
            if (instruction==""){
                instruction = "";
            }*/
        }

        if (list==null){
            WorldViewServerCommunication.setError("Did not find words");
            return;
        }else if(list.Count==0){
            WorldViewServerCommunication.setError("List of words is empty");
            return;
        }else{

            foreach(PackagedNextWord w in list){
                if (w.getAnnotatedWord().getWordProblems().Count==0){
                    WorldViewServerCommunication.setError("Word '"+w.getAnnotatedWord().getWord()+"' do not have problems");
                    return;
                }else if(w.getAnnotatedWord().getWordProblems()[0].matched.Length==0){
                    WorldViewServerCommunication.setError("Word '"+w.getAnnotatedWord().getWord()+"' do not have problems");
                    return;
                }
            }
        }

        /*if (error){
            list = WordDBCreator.createListPackagedNextWords("HARVEST");
            level = new LevelParameters(WordDBCreator.getLevel("HARVEST"));
        }*/

        lvlArr = new HarvestLevelConfig[list.Count];

        int idx = 0;

        List<string> patterns = new List<string>();

        try{

        Difficulty[][] profileDifficulties = WorldViewServerCommunication.userProfile.userProblems.getDifficultiesDescription().getDifficulties();

        if (level.mode==0){

            patterns.Add("Open syllable");
            //patterns.Add("Muuuuuu");
            patterns.Add("Closed syllable");
            //patterns.Add("Muuuuuu");

            foreach(PackagedNextWord nw in list){

                List<int> matches = new List<int>();

                string[] cvForm = nw.getAnnotatedWord().getCVForm().Split(new char[] {'-'}, System.StringSplitOptions.RemoveEmptyEntries);
                if (cvForm[0][cvForm[0].Length-1]=='v'){
                    matches.Add(0);
                }else{
                    matches.Add(1);

                }

                /*if(cvForm.Length>1){

                    if (cvForm[1][cvForm[1].Length-1]=='v')
                        matches.Add(2);
                    else
                        matches.Add(3);
                }*/

                lvlArr[idx++] = new HarvestLevelConfig(nw.getAnnotatedWord().getWord(),patterns.ToArray(),matches.ToArray(), nw.getAnnotatedWord().getWordProblems()[0].category,nw.getAnnotatedWord().getWordProblems()[0].index);
            }

        }else if(level.mode==1){

            //int lA = 0;
            foreach(PackagedNextWord nw in list){
                //foreach(WordProblemInfo wp in nw.getAnnotatedWord().getWordProblems()){
                WordProblemInfo wp = nw.getAnnotatedWord().getWordProblems()[0];
                Debug.Log(nw.getAnnotatedWord().getWord()+" "+profileDifficulties[ wp.category ][ wp.index  ].character);

                string problem = profileDifficulties[ wp.category ][ wp.index  ].character;//getDescriptionsToString();
                if(!patterns.Contains(problem)){
                    patterns.Add(problem);
                    //lA = wp.category;
                }
                //}
            }

            /*List<string> candidates = new List<string>();

            for(int i = 0; i < profileDifficulties[lA].Length;i++){

                if (!candidates.Contains(profileDifficulties[lA][i].character)){
                    candidates.Add(profileDifficulties[lA][i].character);
                }
            }

            while((patterns.Count<4)&(candidates.Count>0)){

                int index = Random.Range(0,candidates.Count);
                string candidateCharacter = candidates[index];

                patterns.Add(candidateCharacter);

                candidates.Remove(candidateCharacter);

            }*/

            List<HarvestLevelConfig> array = new List<HarvestLevelConfig>();

            //while(patterns.Count<4)
            //	patterns.Add("Muuuuuu");

            foreach(PackagedNextWord nw in list){

                List<int> matches = new List<int>();

                WordProblemInfo wp = nw.getAnnotatedWord().getWordProblems()[0];
                string problem = profileDifficulties[ wp.category ][ wp.index  ].character;//getDescriptionsToString();

                for(int i = 0;i<patterns.Count;i++){

                    if(patterns[i]==problem){
                        matches.Add(i);
                    }
                }

                if (matches.Count>0)
                    array.Add(new HarvestLevelConfig(nw.getAnnotatedWord().getWord(),patterns.ToArray(),matches.ToArray(),nw.getAnnotatedWord().getWordProblems()[0].category,nw.getAnnotatedWord().getWordProblems()[0].index));

            }

            lvlArr = array.ToArray();

        }else if(level.mode==2){

            foreach(PackagedNextWord nw in list){//confusing lettershapes
                //foreach(WordProblemInfo wp in nw.getAnnotatedWord().getWordProblems()){

                WordProblemInfo wp = nw.getAnnotatedWord().getWordProblems()[0];

                string problem = profileDifficulties[ wp.category ][ wp.index  ].getDescriptionsToString();

                if(!patterns.Contains(problem.Split('/')[0])){
                    patterns.Add(problem.Split('/')[0]);
                }

                if(!patterns.Contains(problem.Split('/')[1])){
                    patterns.Add(problem.Split('/')[1]);
                }
                //}
            }

            while(patterns.Count<4){

                int lA = list[0].getAnnotatedWord().getWordProblems()[0].category;
                int i = Random.Range(0,profileDifficulties[lA].Length);

                string problem = profileDifficulties[ lA ][ i  ].getDescriptionsToString();

                if(!patterns.Contains(problem.Split('/')[0])){
                    patterns.Add(problem.Split('/')[0]);
                }

                if(!patterns.Contains(problem.Split('/')[1])){
                    patterns.Add(problem.Split('/')[1]);
                }
            }

            foreach(PackagedNextWord nw in list){

                List<int> matches = new List<int>();

                for(int i = 0;i<patterns.Count;i++){

                    if(nw.getAnnotatedWord().getWord().IndexOf(patterns[i])>-1){
                        matches.Add(i);
                    }
                }
                lvlArr[idx++] = new HarvestLevelConfig(nw.getAnnotatedWord().getWord(),patterns.ToArray(),matches.ToArray(),nw.getAnnotatedWord().getWordProblems()[0].category,nw.getAnnotatedWord().getWordProblems()[0].index);

            }

        }else if(level.mode==3){//gr//NOT USED

            foreach(PackagedNextWord nw in list){
                //foreach(WordProblemInfo wp in nw.getAnnotatedWord().getWordProblems()){

                string problem =   nw.getAnnotatedWord().getSyllables().Length.ToString();

                if(!patterns.Contains(problem)){
                    patterns.Add(problem);
                }
                if (patterns.Count==4)
                    break;
                //}
            }

            if(patterns.Count<4){
                for (int i=2;i<6;i++){

                    if(!patterns.Contains(i.ToString()))
                        patterns.Add(i.ToString());

                    if (patterns.Count==4)
                            break;

                }
            }

            foreach(PackagedNextWord nw in list){

                List<int> matches = new List<int>();

                string problem = nw.getAnnotatedWord().getSyllables().Length.ToString();

                for(int i = 0;i<patterns.Count;i++){

                    if(patterns[i]==problem){
                        matches.Add(i);
                    }
                }
                if (matches.Count!=0)
                    lvlArr[idx++] = new HarvestLevelConfig(nw.getAnnotatedWord().getWord(),patterns.ToArray(),matches.ToArray(),nw.getAnnotatedWord().getWordProblems()[0].category,nw.getAnnotatedWord().getWordProblems()[0].index);
            }

        }else if(level.mode==4){//Function words

            foreach(PackagedNextWord nw in list){
                //foreach(WordProblemInfo wp in nw.getAnnotatedWord().getWordProblems()){

                string problem =   nw.getAnnotatedWord().getType();

                if(!patterns.Contains(problem)){
                    patterns.Add(problem);
                }
                if (patterns.Count==4)
                    break;
                //}
            }

            //while(patterns.Count<4){

            //			patterns.Add("Muuuuuu");

            //}

            foreach(PackagedNextWord nw in list){

                List<int> matches = new List<int>();

                string problem = nw.getAnnotatedWord().getType();

                for(int i = 0;i<patterns.Count;i++){

                    if(patterns[i]==problem){
                        matches.Add(i);
                    }
                }
                if (matches.Count!=0)
                    lvlArr[idx++] = new HarvestLevelConfig(nw.getAnnotatedWord().getWord(),patterns.ToArray(),matches.ToArray(),nw.getAnnotatedWord().getWordProblems()[0].category,nw.getAnnotatedWord().getWordProblems()[0].index);
            }

        }else if(level.mode==5){

            List<string> problems = new List<string>();
            List<int> wordsCount = new List<int>();

            foreach(PackagedNextWord nw in list){
                foreach(WordProblemInfo wp in nw.getAnnotatedWord().getWordProblems()){

                    string problem = nw.getAnnotatedWord().getWord().Substring(wp.matched[0].start,wp.matched[0].end-wp.matched[0].start);

                    if(!problems.Contains(problem)){
                        //Debug.Log("New! "+nw.getAnnotatedWord().getWord()+" "+problem);
                        problems.Add(problem);
                        wordsCount.Add (1);
                    }else{
                        //Debug.Log("Old! "+nw.getAnnotatedWord().getWord()+" "+problem);

                        next_string_pattern = problem;
                        int i = problems.FindIndex(FindString);
                        wordsCount[i] = wordsCount[i]+1;

                    }
                }

            }

            List<string> validPatterns = new List<string>();
            List<string> needRepresentative = new List<string>();
            List<string> bench = new List<string>();

            for(int i =0;i<problems.Count;i++){

                if( wordsCount[i]>1){
                    validPatterns.Add(problems[i]);
                    needRepresentative.Add(problems[i]);
                }else{

                    bench.Add(problems[i]);
                }
                if (validPatterns.Count==4)
                    break;

            }

            //Debug.Log(validPatterns.Count);

            foreach(string w in bench){
                if(validPatterns.Count<4){
                    validPatterns.Add(w);
                    needRepresentative.Add(w);
                }else
                    break;
            }

            while(validPatterns.Count<4){
                string newPattern = validPatterns[Random.Range(0,validPatterns.Count)];
                validPatterns.Add(newPattern);
                needRepresentative.Add(newPattern);
            }
            //Debug.Log(validPatterns.Count);

            List<PackagedNextWord> words = new List<PackagedNextWord>();

            foreach(PackagedNextWord nw in list){

                bool representative = false;
                foreach(WordProblemInfo wp in nw.getAnnotatedWord().getWordProblems()){

                    string problem = nw.getAnnotatedWord().getWord().Substring(wp.matched[0].start,wp.matched[0].end-wp.matched[0].start);

                    if(needRepresentative.Contains(problem)){
                        patterns.Add(nw.getAnnotatedWord().getWord());
                        needRepresentative.Remove(problem);
                        representative = true;
                        break;
                    }
                }
                if(!representative)
                    words.Add(nw);

            }

            List<HarvestLevelConfig> array = new List<HarvestLevelConfig>();
            //Debug.Log(patterns.Count);

            foreach(PackagedNextWord nw in words){

                List<int> matches = new List<int>();
                for(int i = 0; i<validPatterns.Count;i++){

                    foreach(WordProblemInfo wp in nw.getAnnotatedWord().getWordProblems()){

                        string problem = nw.getAnnotatedWord().getWord().Substring(wp.matched[0].start,wp.matched[0].end-wp.matched[0].start);

                        if (validPatterns[i]==problem){
                            matches.Add(i);
                            //Debug.Log("break?");
                            break;
                        }

                    }
                }
                //Debug.Log(nw.getAnnotatedWord().getWord()+" "+matches.Count);
                if(matches.Count>0){
                    array.Add(new HarvestLevelConfig(nw.getAnnotatedWord().getWord(),patterns.ToArray(),matches.ToArray(),nw.getAnnotatedWord().getWordProblems()[0].category,nw.getAnnotatedWord().getWordProblems()[0].index));
                    if(array.Count==level.batchSize)
                        break;
                }
            }
            lvlArr = array.ToArray();

        }else if(level.mode==6){

            List<int> numberSyllables = new List<int>();
            List<int> wordsCount = new List<int>();

            foreach(PackagedNextWord nw in list){
                //foreach(WordProblemInfo wp in nw.getAnnotatedWord().getWordProblems()){

                int syllables =   nw.getAnnotatedWord().getSyllables().Length;

                if(!numberSyllables.Contains(syllables)){
                    numberSyllables.Add(syllables);
                    wordsCount.Add (1);
                }else{
                    next_int_pattern = syllables;
                    int i = numberSyllables.FindIndex(FindInt);

                    wordsCount[i] = wordsCount[i]+1;

                }

            }

            List<int> validPatterns = new List<int>();
            List<int> bench = new List<int>();
            List<int> needRepresentative = new List<int>();

            for(int i =0;i<numberSyllables.Count;i++){

                if( wordsCount[i]>1){
                    //validPatterns.Add(numberSyllables[i]);
                    needRepresentative.Add(numberSyllables[i]);
                }else{

                    bench.Add(numberSyllables[i]);

                }

                if (needRepresentative.Count==4)
                        break;

            }

                //Debug.Log(validPatterns.Count);

                foreach(int w in bench){
                    if(needRepresentative.Count<4){
                        //validPatterns.Add(w);
                        needRepresentative.Add(w);
                    }else
                        break;
                }

            while(needRepresentative.Count<4){
                int newPattern = needRepresentative[Random.Range(0,needRepresentative.Count)];
                //validPatterns.Add(newPattern);
                needRepresentative.Add(newPattern);
            }

            List<PackagedNextWord> words = new List<PackagedNextWord>();

            //string[] patternsArray = new string[needRepresentative.Count];

            foreach(PackagedNextWord nw in list){
                //foreach(WordProblemInfo wp in nw.getAnnotatedWord().getWordProblems()){

                int syllables = nw.getAnnotatedWord().getSyllables().Length;

                if(needRepresentative.Contains(syllables)){
                    validPatterns.Add(syllables);
                    patterns.Add(nw.getAnnotatedWord().getWord());
                    needRepresentative.Remove(syllables);
                }else if(validPatterns.Contains(syllables)){
                    words.Add(nw);
                    //Debug.Log("WORD "+nw.getAnnotatedWord().getWord());
                }

            }

            List<HarvestLevelConfig> array = new List<HarvestLevelConfig>();
            foreach(PackagedNextWord nw in words){

                List<int> matches = new List<int>();
                int syllables = nw.getAnnotatedWord().getSyllables().Length;

                for(int i = 0; i<validPatterns.Count;i++)
                    if (validPatterns[i]==syllables)
                        matches.Add(i);

                if(matches.Count>0){
                    array.Add(new HarvestLevelConfig(nw.getAnnotatedWord().getWord(),patterns.ToArray(),matches.ToArray(),nw.getAnnotatedWord().getWordProblems()[0].category,nw.getAnnotatedWord().getWordProblems()[0].index));
                    if(array.Count==level.batchSize)
                        break;
                }

            }

            lvlArr = array.ToArray();

        }

        for(int i= 1;i<lvlArr.Length;i++){

            int j = Random.Range(1,lvlArr.Length);

            HarvestLevelConfig a = lvlArr[i];
            lvlArr[i] = lvlArr[j];
            lvlArr[j] = a;

        }

        }catch(System.Exception e){

        WorldViewServerCommunication.setError(e.Message);
        return;
        }

        counter = 0;
    }
예제 #10
0
    void Awake()
    {
        Debug.Log("ProgressScript is Awake");

        GameObject servComObj = getServerObject();

        wvServCom = servComObj.GetComponent<WorldViewServerCommunication>();
        acServCom = servComObj.GetComponent<ActivityServerCommunication>();

        if((wvServCom == null)||(acServCom==null))
        {
            Debug.LogError("Something went wrong; WorldViewServerCommunication should be ready");
            wvServCom = servComObj.AddComponent<WorldViewServerCommunication>();
            acServCom = servComObj.AddComponent<ActivityServerCommunication>();

            loading = -1;
        }else{

            loading = 0;
        }
    }