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; }
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; }