Beispiel #1
0
        public string GenerateWord(int size_x, bool use_size)
        {
            int letter;
            int pos_x;
            string word = "";
            ValueMap letters = new ValueMap(size_x, 1);
            Sample key = new Sample(SAMPLE_X);

            // Init the random number generator
            randgen.Init();
            pos_x = 0;
            letter = -1;
            while (pos_x < size_x)
            {
                // find the letter
                key = GetSample(letters, pos_x);
                letter = GenerateIndex(key, use_size);
                letters.SetValue(letter, pos_x, 0);
                if (letter >= (GRID_SIZE - 1))
                {
                    break;
                }
                if (letter < 0)
                {
                    break;
                }
                pos_x++;
            }
            for (pos_x = 0; pos_x < size_x; pos_x++)
            {
                letter = letters.GetValue(pos_x, 0);
                // if color does not exist, exit
                if (letter < 0)
                {
                    return word;
                }
                if (letter >= (GRID_SIZE - 1))
                {
                    return word;
                }
                word += char_set.GetLetter((int)(letter - 1));
            }
            return word;
        }
Beispiel #2
0
 public Sample GetSample(ValueMap letters, int pos_x)
 {
     Sample key = new Sample(SAMPLE_X);
     int x = pos_x - SAMPLE_X + 1;
     for (int i = 0; i < SAMPLE_X; i++)
     {
         if ((x + i) < 0) key.Set(0, i);
         else if ((x + i) >= letters.GetSizeX()) key.Set(GRID_SIZE - 1, i);
         else key.Set(letters.GetValue(x + i, 0), i);
     }
     return key;
 }
Beispiel #3
0
        ValueMap ProcessWord(string word)
        {
            int size = word.Length;
            ValueMap map = new ValueMap(size, 1);

            for (int i = 0; i < size; i++)
            {
                map.SetValue(char_set.GetIndex(word[i]) + 1, i, 0);
            }
            return map;
        }
Beispiel #4
0
 void LearnWord(ValueMap word)
 {
     int size_x, pos_x;
     size_x = word.GetSizeX();
     // Add the letters to the table
     for (pos_x = 1 - SAMPLE_X; pos_x < size_x; pos_x++)
     {
         int x = pos_x + SAMPLE_X - 1;
         Sample patch = GetSample(word, x);
         AddUsage(patch);
     }
 }