Пример #1
0
    private bool IsCorrectOverlap(SWord w1, SWord w2)
    {
        if (w1.WordDirection == w2.WordDirection)
        {
            return(false);
        }

        int i1, i2;

        if (w1.WordDirection == WordDirection.Horizontal)
        {
            i1 = w1.X - w2.X;
            i2 = w2.Y - w1.Y;
        }
        else
        {
            i1 = w1.Y - w2.Y;
            i2 = w2.X - w1.X;
        }

        if (i1 < 0 || i1 >= w1.Length)
        {
            return(false);
        }

        if (i2 < 0 || i2 >= w2.Length)
        {
            return(false);
        }

        return(w1.Name[i1] == w2.Name[i2]);
    }
Пример #2
0
    private List <SWord> GetWordPlacements(SWord newWord)
    {
        List <SWord> placements = new List <SWord>();

        foreach (SWord usedWord in _usedWords)
        {
            foreach (Vector2 location in _clDictionary[usedWord.Name][newWord.Name])
            {
                if (usedWord.WordDirection == WordDirection.Horizontal)
                {
                    newWord.WordDirection = WordDirection.Vertical;
                    newWord.X             = (int)(usedWord.X - location.x);
                    newWord.Y             = (int)(usedWord.Y + location.y);
                }
                else
                {
                    newWord.WordDirection = WordDirection.Horizontal;
                    newWord.X             = (int)(usedWord.X + location.y);
                    newWord.Y             = (int)(usedWord.Y - location.x);
                }

                int matchCount = PlaceWord(newWord);

                if (matchCount > 0)
                {
                    placements.Add(new SWord(newWord, matchCount));
                }
            }
        }

        return(placements);
    }
Пример #3
0
 public SWord(SWord word, int matchCount)
 {
     Name          = word.Name;
     WordDirection = word.WordDirection;
     X             = word.X;
     Y             = word.Y;
     MatchCount    = matchCount;
     LocationList  = word.LocationList;
 }
Пример #4
0
    private bool IsWordsOverlap(SWord w1, SWord w2)
    {
        if (w1.X < w2.XMin || w2.X < w1.XMin)
        {
            return(false);
        }

        if (w1.Y < w2.YMin || w2.Y < w1.YMin)
        {
            return(false);
        }


        return(true);
    }
Пример #5
0
    public IEnumerator MakeWordSet()
    {
        Initialize();

        SWord word  = null;
        int   index = 0;

        var startTime = Time.time;

        while (_foundResultCount < MaxResults || Time.time < startTime + _words.Count * 2)
        {
            MgsCoroutine.Info = _foundResultCount + " word set found.";
            if (BruteForce)
            {
                if (index < _words.Count)
                {
                    word = _words[index++];
                }
                else
                {
                    break;
                }
            }
            else
            {
                word = _words[Random.Range(0, _words.Count)];
            }

            word.X             = 0;
            word.Y             = 0;
            word.WordDirection = WordDirection.Horizontal;

/*            if (_foundResultCount >= MaxResults)
 *              break;*/

            yield return(TryOtherWords(word));
        }

        if (_foundResultCount == 0)
        {
            Successful = false;
            yield break;
        }


        print(_foundResultCount + " WordSet Found");
        Successful = true;
    }
Пример #6
0
    private int PlaceWord(SWord newWord)
    {
        int count = 0;

        foreach (SWord usedWord in _usedWords)
        {
            if (IsWordsOverlap(usedWord, newWord))
            {
                if (IsCorrectOverlap(usedWord, newWord))
                {
                    count++;
                }
                else
                {
                    return(-1);
                }
            }
        }

        return(count);
    }
Пример #7
0
    public static SWord Create(SWord inWord)
    {
        SWord outWord = inWord;

        return(outWord);
    }
Пример #8
0
        void PrepareText(string text)         //matn kiritiladi
        {
            //using(var fs = File.OpenText("temp.txt"))
            //{
            //	tempString = fs.ReadToEnd();
            //}
            rtbx.Document.Blocks.Clear();
            runsList = new List <Run>();
            var paragraphs = text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);             //matnni abzatslarga bo'ladi

            int[]         sentencesInParagraph = new int[paragraphs.Length];
            List <string> gaplar = new List <string>();

            for (int i = 0; i < paragraphs.Length; i++)
            {
                var tempgaplar = regex.Split(paragraphs[i]);
                sentencesInParagraph[i] = tempgaplar.Length;
                foreach (string s in tempgaplar)
                {
                    gaplar.Add(s);
                }
            }
            //var gaplar = regex.Matches(text);
            Gaplar = new List <TWord[]>();
            var missingSlogs = new List <string>();
            int slogIndex = 0, lastSlogIndex;

            //for (int i = 0; i < gaplar.Count; i++)
            for (int i = 0; i < gaplar.Count; i++)
            {
                //var suzlar = WordDivider.GetWords(gaplar[i].Value);
                var suzlar = WordDivider.GetWords(gaplar[i]);
                if (suzlar != null)
                {
                    TWord[] words = new TWord[suzlar.Length];
                    for (int j = 0; j < suzlar.Length; j++)
                    {
                        var     sloglar = analyzer.Analyze(suzlar[j]);
                        SWord[] sWords  = null;
                        if (sloglar != null)
                        {
                            lastSlogIndex = sloglar.Length - 1;
                            sWords        = new SWord[sloglar.Length];
                            for (int l = 0; l < sloglar.Length; l++)
                            {
                                try
                                {
                                    if (l == 0)
                                    {
                                        if (sloglar[l] == suzlar[j])
                                        {
                                            slogIndex = 0;
                                        }
                                        else
                                        {
                                            slogIndex = 1;
                                        }
                                    }
                                    else
                                    {
                                        if (l == lastSlogIndex)
                                        {
                                            slogIndex = 3;
                                        }
                                        else
                                        {
                                            slogIndex = 2;
                                        }
                                    }
                                    var audioPath = GetAudioPath(sloglar[l], slogIndex);
                                    if (audioPath != null)
                                    {
                                        sWords[l] = new SWord()
                                        {
                                            Syllable = sloglar[l], TWavPath = audioPath
                                        }
                                    }
                                    ;                                                                                                                    // [0] ni o'rniga bo'g'inni so'zni qayerida kelishini yozish kerak
                                    else
                                    {
                                        if (!notFounList.Contains(audioPath))
                                        {
                                            notFounList.Add(audioPath);
                                        }
                                    }
                                }
                                catch
                                {
                                    missingSlogs.Add(sloglar[l]);
                                }
                            }
                        }
                        words[j] = new TWord()
                        {
                            Word = suzlar[j], Syllables = sWords
                        };
                        words[j].Init();
                    }
                    Gaplar.Add(words);
                }
            }
            using (var sw = File.AppendText("NotFoundedAudioFiles.txt"))
            {
                for (int i = 0; i < notFounList.Count; i++)
                {
                    sw.WriteLine(notFounList[i]);
                }
            }
            //using (var sw = File.CreateText("TextData.json"))
            //{
            //	sw.Write(JsonConvert.SerializeObject(Gaplar, Formatting.Indented));
            //}
            if (gaplar.Count > 0)
            {
                for (int i = 0, j = 0; i < sentencesInParagraph.Length; i++)
                {
                    //string s = paragraphs[i];
                    //if (gaplar.Count > 0)
                    var p = new Paragraph();
                    for (int l = 0; l < sentencesInParagraph[i]; l++)
                    {
                        string gap = gaplar[j];
                        //var str = gap.Value.Trim();
                        var str      = gap.Trim();
                        var run      = new Run(str);
                        var emptyrun = new Run(" ");
                        run.FontStretch          = FontStretches.UltraExpanded;
                        run.MouseEnter          += Run_MouseEnter;
                        run.MouseLeave          += Run_MouseLeave;
                        run.MouseLeftButtonDown += Run_MouseLeftButtonDownAsync;
                        p.Inlines.Add(run);
                        p.Inlines.Add(emptyrun);

                        runsList.Add(run);
                        j++;
                    }
                    p.Inlines.Remove(p.Inlines.LastInline);
                    rtbx.Document.Blocks.Add(p);
                }
            }
        }
Пример #9
0
    private void SpawnWord(SWord sWord)
    {
        // Word component
        Word wordComponent = (Word)PoolManager.Instance.Get(WordPrefab, WordManager.transform);

        wordComponent.IsComplete = false;

        if (wordComponent.Letters == null)
        {
            wordComponent.Letters = new List <Letter>();
        }
        else
        {
            wordComponent.Letters.Clear();
        }

        wordComponent.Direction       = sWord.WordDirection;
        wordComponent.Name            = sWord.Name;
        wordComponent.gameObject.name = PersianFixer.Fix(sWord.Name);

        for (int i = 0; i < sWord.Name.Length; i++)
        {
            Letter letter = null;

            if (_locationDictionary.ContainsKey(sWord.Locations(i)))
            {
                letter = _locationDictionary[sWord.Locations(i)];
            }
            else
            {
                if (!Application.isPlaying)
                {
                    if (EditorInstatiate != null)
                    {
                        letter = EditorInstatiate(LetterPrefab);
                    }
                    else
                    {
                        Debug.LogError("EditorInstatiate not set !!!");
                    }

                    letter.transform.parent = LetterController.transform;
                }
                else
                {
                    letter = (Letter)PoolManager.Instance.Get(
                        LetterPrefab,
                        LetterController.transform);
                }

                // Position
                letter.transform.position = (Vector3)sWord.Locations(i) - _bounds.center;

                // Name
                letter.name = "Letter " + sWord.Name[i];
                letter.Char = sWord.Name[i];
                // TextMesh
                letter.SetCharacter(sWord.Name[i]);

                // LetterController
                LetterController.AllLetters.Add(letter);

                // Add to Dictionary
                _locationDictionary.Add(sWord.Locations(i), letter);
            }

            wordComponent.Letters.Add(letter);
            letter.gameObject.SetActive(false);
        }

        if (Application.isPlaying)
        {
            StartCoroutine(CameraController.FocusAllLetters());
            if (SpawnPartByPart)
            {
                StartCoroutine(EnableParts());
            }
            else
            {
                LetterController.AllLetters.ForEach(l => l.gameObject.SetActive(true));
            }
        }
        else
        {
            LetterController.AllLetters.ForEach(l => l.gameObject.SetActive(true));
        }
    }
Пример #10
0
    private IEnumerator TryOtherWords(SWord lastWord)
    {
        // Show Progress Bar
        MgsCoroutine.Info       = _foundResultCount.ToString("N0") + " WordSet Found";
        MgsCoroutine.Percentage = _foundResultCount / (float)MaxResults;

        yield return(null);

        // Safe Guard
        if (_foundResultCount > MaxResults)
        {
            yield break;
        }


        // Use last word
        _usedWords.Add(lastWord);

        if (_usedWords.Count >= UsedWordCount)
        {
            // FIND A CORRECT PUZZLE !!!
            ResultFound();
        }
        else
        {
            List <SWord> _unusedWords = _words.Where(w => _usedWords.Find(uw => uw.Name == w.Name) == null).ToList();

            int   index = 0;
            SWord word  = null;

            while (_unusedWords.Count > 0)
            {
                if (!BruteForce)
                {
                    index = Random.Range(0, _unusedWords.Count);
                    word  = _unusedWords[index];
                    _unusedWords.RemoveAt(index);
                }
                else
                {
                    if (index < _unusedWords.Count)
                    {
                        word = _unusedWords[index++];
                    }
                    else
                    {
                        break;
                    }
                }

                if (_usedWords.Find(w => w.Name == word.Name) == null)
                {
                    List <SWord> placements = GetWordPlacements(word);

                    foreach (var w in placements)
                    {
                        yield return(TryOtherWords(w));
                    }
                }
            }
        }

        // Unused last word
        _usedWords.Remove(lastWord);
    }