Exemple #1
0
        public Sample(Sample sample)
        {
            this.MAX_SIZE = sample.MAX_SIZE;
            values = new List<int>(MAX_SIZE);

            for (int i = 0; i < MAX_SIZE; i++)
            {
                values.Add(sample.values[i]);
            }
            this.level = sample.level;
        }
Exemple #2
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;
        }
Exemple #3
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;
 }
Exemple #4
0
 int GetUsageCount(Sample key)
 {
     if (usage.ContainsKey(key))
     {
         return usage[key];
     }
     return 0;
 }
Exemple #5
0
        int GenerateIndex(Sample sample, bool use_size)
        {
            int counter;
            int total, freq, letter;
            int end = (use_size ? 1 : 0);

            // Get the frequencies
            total = 0;
            for (counter = 1; counter < (GRID_SIZE - end); counter++)
            {
                Sample key = new Sample(sample);
                key.Set(counter, (SAMPLE_X - 1));
                total += GetUsageCount(key);
            }

            // Choose a 'target' frequency
            if (total > 0)
            {
                letter = (randgen.NextInt() % total) + 1;
            }
            else
            {
                return -1; // no solution
            }
            // Move through the table until we hit the 'target' frequency
            counter = 1;
            freq = 0;
            do
            {
                Sample key = new Sample(sample);
                key.Set(counter, (SAMPLE_X - 1));
                freq += GetUsageCount(key);
                counter++;
            } while (freq < letter);
            return counter - 1;
        }
Exemple #6
0
 void AddUsage(Sample key)
 {
     if (!usage.ContainsKey(key))
     {
         usage.Add(key, 0);
     }
     usage[key]++;
 }
Exemple #7
0
 public int VectorDistance(Sample patch)
 {
     int dot = 0;
     for (int i = 0; i < MAX_SIZE; i++)
     {
         int diff =
             (this.values[i] - patch.values[i]);
         dot += (diff * diff);
     }
     return (int)(Math.Sqrt(dot));
 }